-
Notifications
You must be signed in to change notification settings - Fork 178
/
Copy pathApples and Bananas.cpp
63 lines (53 loc) · 1.32 KB
/
Apples and Bananas.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
typedef double ld;
typedef complex<ld> cd;
const int SIZE = 1<<19;
const ld PI = acos(-1);
int N, M, K;
vector<cd> A(SIZE), B(SIZE);
void fft(vector<cd> &a, bool inv){
int N = (int) a.size();
for(int i = 1, j = 0; i < N; i++){
int bit = N>>1;
for(; j&bit; bit >>= 1)
j ^= bit;
j ^= bit;
if(i < j)
swap(a[i], a[j]);
}
for(int len = 2; len <= N; len <<= 1){
ld theta = 2*PI / len * (inv ? -1 : 1);
cd wlen(cos(theta), sin(theta));
for(int i = 0; i < N; i += len){
cd w(1);
for(int j = 0; j < len / 2; j++){
cd u = a[i+j], v = a[i+j+len/2] * w;
a[i+j] = u + v;
a[i+j+len/2] = u - v;
w *= wlen;
}
}
}
if(inv)
for(cd &z : a)
z /= N;
}
int main(){
scanf("%d %d %d", &K, &N, &M);
for(int i = 0, x; i < N; i++){
scanf("%d", &x);
A[x] += 1;
}
for(int i = 0, x; i < M; i++){
scanf("%d", &x);
B[x] += 1;
}
fft(A, false);
fft(B, false);
for(int i = 0; i < SIZE; i++)
A[i] *= B[i];
fft(A, true);
for(int i = 2; i <= 2*K; i++)
printf("%lld%c", llround(A[i].real()), (" \n")[i==2*K]);
}