Aiiage Camp Day3 G Gatehouse
阿新 • • 發佈:2018-02-11
分享 style font 裸題 clas return class scan %d
題意
求↓
op是異或。
n=2^k, 1<=k<=17
題解
FWT裸題..甚至在題面告知了模板名..
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 void FWT(long long a[], int n) 5 { 6 for (int d = 1; d < n; d <<= 1) 7 for (int m = d << 1, i = 0; i < n; i += m) 8 for(int j = 0; j < d; ++j) 9 { 10 long long x = a[i + j], y = a[i + j + d]; 11 a[i + j] = x + y; 12 } 13 } 14 15 void UFWT(long long a[], int n) 16 { 17 for (int d = 1; d < n; d <<= 1) 18 for (int m = d << 1, i = 0; i < n; i += m)19 for (int j = 0; j < d; ++j) 20 { 21 long long x = a[i + j], y = a[i + j + d]; 22 a[i + j] = x - y; 23 } 24 } 25 26 long long a[200000], b[200000]; 27 28 int main() 29 { 30 int k; 31 scanf("%d", &k); 32 int n = pow(2, k);33 for (int i = 0; i < n; ++i) 34 scanf("%lld", a + i); 35 for (int i = 0; i < n; ++i) 36 scanf("%lld", b + i); 37 FWT(a, n); 38 FWT(b, n); 39 for (int i = 0; i < n; ++i) 40 a[i] = a[i] * b[i]; 41 UFWT(a, n); 42 for (int i = 0; i < n; ++i) 43 printf("%lld\n", a[i]); 44 45 return 0; 46 }
Aiiage Camp Day3 G Gatehouse