标签:algorithm har csuoj ase names problems tchar vector \n
FWT模板题
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 530005,maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
return flag ? out : -out;
}
inline int RD(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 1) + c - 48; c = getchar();}
return flag ? out : -out;
}
LL A[maxn],B[maxn];
void fwt(LL* a,int n,int f){
for (int i = 1; i < n; i <<= 1)
for (int j = 0; j < n; j += (i << 1))
for (int k = 0; k < i; k++)
a[j + k + i] += a[j + k] * f;
}
int main(){
int T = read();
for (int C = 1; C <= T; C++){
printf("Case #%d:\n",C);
int n = read(),m = read(),deg = 1;
cls(A,0); cls(B,0);
while (deg <= (1 << m)) deg <<= 1;
REP(i,n) A[RD()]++;
REP(i,n) B[RD()]++;
fwt(A,deg,1); fwt(B,deg,1);
for (int i = 0; i < deg; i++) A[i] *= B[i];
fwt(A,deg,-1);
int Q = read();
while (Q--) printf("%lld\n",A[RD()]);
}
return 0;
}
标签:algorithm har csuoj ase names problems tchar vector \n
原文地址:https://www.cnblogs.com/Mychael/p/9256724.html