# [BZOJ3771]Triple

[BZOJ3771]Triple

“这把斧头，是不是你的？”

“这把斧头，是不是你的？”

“这把斧头，是不是你的？”

“你看看你现在的样子，真是丑陋！”

4
4
5
6
7

4 1
5 1
6 1
7 1
9 1
10 1
11 2
12 1
13 1
15 1
16 1
17 1
18 1

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std;

const int BufferSize = 1 << 16;
inline char Getchar() {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
}
int x = 0, f = 1; char c = Getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = Getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = Getchar(); }
return x * f;
}

#define maxn 240010
#define LL long long
const double pi = acos(-1.0);
struct Complex {
double a, b;
Complex() { a = b = 0.0; }
Complex operator + (const Complex& t) const {
Complex ans;
ans.a = a + t.a;
ans.b = b + t.b;
return ans;
}
Complex operator += (const Complex& t) {
*this = *this + t;
return *this;
}
Complex operator - (const Complex& t) const {
Complex ans;
ans.a = a - t.a;
ans.b = b - t.b;
return ans;
}
Complex operator * (const Complex& t) const {
Complex ans;
ans.a = a * t.a - b * t.b;
ans.b = a * t.b + b * t.a;
return ans;
}
Complex operator * (const double& t) const {
Complex ans;
ans.a = a * t;
ans.b = b * t;
return ans;
}
Complex operator *= (const Complex& t) {
*this = *this * t;
return *this;
}
} A[maxn], A2[maxn], A3[maxn], ans[maxn];
int n, m;

int Ord[maxn];
void FFT(Complex a[], int n, int tp) {
for(int i = 0; i < n; i++) if(i < Ord[i]) swap(a[i], a[Ord[i]]);
for(int i = 1; i < n; i <<= 1) {
Complex w, wn; wn.a = cos(pi / i); wn.b = sin(pi / i) * tp;
for(int j = 0; j < n; j += (i << 1)) {
w.a = 1.0; w.b = 0.0;
for(int k = 0; k < i; k++) {
Complex t1 = a[j+k], t2 = w * a[j+k+i];
a[j+k] = t1 + t2;
a[j+k+i] = t1 - t2;
w *= wn;
}
}
}
if(tp < 0) for(int i = 0; i <= n; i++) a[i].a = (int)(a[i].a / n + .5);
return ;
}

int main() {
for(int i = 1; i <= t; i++) {
A[x].a += 1.0; A2[x<<1].a += 1.0; A3[x*3].a += 1.0;
n = max(n, x);
}

m = n * 3; int L = 0;
for(n = 1; n <= m; n <<= 1) L++;
for(int i = 0; i < n; i++) Ord[i] = (Ord[i>>1] >> 1) | ((i & 1) << L - 1);
FFT(A, n, 1); FFT(A2, n, 1); FFT(A3, n, 1);
for(int i = 0; i <= n; i++) ans[i] = A[i] + (A[i] * A[i] - A2[i]) * .5 + (A[i] * A[i] * A[i] - A[i] * A2[i] * 3.0 + A3[i] * 2.0) * (1.0 / 6.0);
FFT(ans, n, -1);

for(int i = 1; i <= m; i++) if((int)ans[i].a)
printf("%d %d\n", i, (int)ans[i].a);

return 0;
}


posted @ 2016-08-05 09:27  xjr01  阅读(265)  评论(0编辑  收藏  举报