• 模板


    fft

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef long long ll;
    const double pi=acos(-1);
    typedef complex<double> cp;
    int n,a,q;
    const int mod=100003;
    const int size=1e5+5;
    vector<int> co[size<<2];
    cp x[size],y[size];
    int b[size],s[size];
    int quick_pow(int a,int b){int ans=1;while(b){if(b&1) ans=1LL*a*ans%mod;a=1LL*a*a%mod;b>>=1;} return ans;}
    int fac[size];
    int invfac[size];
    void init()
    {
    	fac[0]=1;
    	for(int i=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%mod;
    	invfac[n]=quick_pow(fac[n],mod-2);
    	for(int i=n-1;i>=0;i--) invfac[i]=1LL*invfac[i+1]*(i+1)%mod;
    }
    namespace Polynomial_multiplication{
    	int n, m, rev[size << 2];
    	cp a[size << 2], b[size << 2];
    	void init(int len) {
    		for (n = 1, m = 0; n <= len; n <<= 1, m++);
    		for (int i = 0; i < n; ++i) {
    			rev[i] = rev[i >> 1] >> 1 | (i & 1) << (m - 1);
    			a[i] = cp(0, 0);
    			b[i] = cp(0, 0);
    		}
    	}
    	void builda(vector<int> x,int len){for(int i=0;i<=len;i++) a[i]=cp(x[i],0);}
    	void builda(int x[],int len){for(int i=0;i<=len;i++) a[i]=cp(x[i],0);}
    	void buildb(vector<int> x,int len){for(int i=0;i<=len;i++) b[i]=cp(x[i],0);}
    	void buildb(int x[],int len){for(int i=0;i<=len;i++) b[i]=cp(x[i],0);}
    	void fft(cp *a, int f) {
    		for (int i = 0; i < n; ++i)if (i < rev[i])swap(a[i], a[rev[i]]);
    		for (int i = 1; i < n; i <<= 1) {
    			double alpha = pi / i;
    			if (f == -1)alpha = -pi / i;
    			for (int k = 0; k < i; ++k) {
    				cp w = cp(cos(alpha*k), sin(alpha*k));
    				for (int j = k; j < n; j += (i << 1)) {
    					cp x = w * a[j + i];
    					a[j + i] = a[j] - x;
    					a[j] += x;
    				}
    			}
    		}
    		if(f==-1) for(int i=0;i<n;i++) a[i]/=n;
    	}
    	void calc(vector<int> &v,int len) {
    		fft(a, 1); fft(b, 1);
    		for (int i = 0; i < n; ++i)a[i] *= b[i];
    		fft(a, -1);
    		for(int i=0;i<=len;i++) v.push_back(LL(a[i].real()+0.5)%mod);
    	}
    } 
    void solve(int id,int l,int r)
    {
    	if(l==r)
    	{
    		co[id].push_back(1);
    		co[id].push_back(b[l]);
    		return ;
    	}
    	int mid=(l+r)/2;
    	solve(id<<1,l,mid);
    	solve(id<<1|1,mid+1,r);
    	Polynomial_multiplication::init(r-l+1);
    	Polynomial_multiplication::builda(co[id<<1],mid-l+1);
    	Polynomial_multiplication::buildb(co[id<<1|1],r-mid);
    	Polynomial_multiplication::calc(co[id],r-l+1);
    }
    
    int ans[size];
    inline LL combi(int k,int n){return k>n?0:1LL*fac[n]*invfac[k]%mod*invfac[n-k]%mod;}
    int main()
    {
    	scanf("%d%d%d",&n,&a,&q);
    	init();
    	for(int i=1;i<=n;i++) scanf("%d",&s[i]);
    	for(int i=1;i<=n;i++) b[i]=quick_pow(a,s[i]%(mod-1));
    	solve(1,1,n);
    	int inva_1=quick_pow(a-1,mod-2);
    	for(int i=1;i<=n;i++) ans[i]=(co[1][i]-combi(i,n)+mod)%mod*inva_1%mod;
    	for(int i=1;i<=q;i++)
    	{
    		int k;
    		scanf("%d",&k);
    		printf("%d
    ",ans[k]);
    	}
    	return 0;
    }
    

    leetcode对于树dp来说可以直接用地址当作key值

    void dfs1(TreeNode* root) {//可以直接使用map<uint32_t,int>
            sum[root] = root -> val;
            if (root -> left) {
                dfs1(root -> left, sum);
                sum[root] += sum[root->left];
            }
            if (root->right) {
                dfs1(root->right, sum);
                sum[root] += sum[root->right];
            }
        }
      
        int dfs2(TreeNode* root) {
            double l, r;
            if (root->left)
               l=dfs2(root->left);
            if (root->right)
               r=[root]+=dfs2(root->right);
               dp[root]+=l+r;
            return dp[root];
        }
        
    
  • 相关阅读:
    js弹出DIV层
    .net 生成静态页面
    新开博客
    随机生成验证码
    ASP.NET错误处理方法总结
    webgis
    看樱花
    今天转载的笑话,挺好笑呵
    用Tomcat插件在Eclipse上搭建可跟踪调试的J2EE WEB开发环境
    关于JSTL的简单说明
  • 原文地址:https://www.cnblogs.com/ttttttttrx/p/11505842.html
Copyright © 2020-2023  润新知