Aiiage Camp Day3 G Gatehouse

题意

  求↓

  

  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 }

 

posted @ 2018-02-11 16:36  Aseer  阅读(119)  评论(0编辑  收藏  举报