Aiiage Camp Day3 G Gatehouse

Posted SUSTech TripleH

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }

 

以上是关于Aiiage Camp Day3 G Gatehouse的主要内容,如果未能解决你的问题,请参考以下文章

Aiiage Camp Day3 I Interpreter

Aiiage Camp Day3 C Communist

Aiiage Camp Day6 J Sort

Aiiage Camp Day4 C KTV

Aiiage Camp Day2 D domino

Aiiage Camp Day4 K Tree game