# BZOJ4836: [Lydsy1704月赛]二元运算【分治FFT】【卡常（没卡过）】

2
2 1 5
1 3
2
1 2 3 4 5
2 2 5
1 3
2 4
1 2 3 4 5

1
0
1
0
0
1
0
1
0
1

## 思路

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

namespace io {

const int BUFSIZE = 1 << 20;
char ibuf[BUFSIZE], *is = ibuf, *it = ibuf;
char obuf[BUFSIZE], *os = obuf, *ot = obuf + BUFSIZE - 1;

if (is == it)
it = (is = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
return *is++;
}

int x = 0, f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
}
while (isdigit(c)) x = x * 10 + c - '0', c = read_char();
return x * f;
}

ll x = 0, f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
}
while (isdigit(c)) x = x * 10 + c - '0', c = read_char();
return x * f;
}

while (!isspace(c)) *s++ = c, c = read_char();
*s = 0;
}

void flush() {
fwrite(obuf, 1, os - obuf, stdout);
os = obuf;
}

void print_char(char c) {
*os++ = c;
if (os == ot) flush();
}

void print_int(int x) {
static char q[20];
if (!x) print_char('0');
else {
if (x < 0) print_char('-'), x = -x;
int top = 0;
while (x) q[top++] = x % 10 + '0', x /= 10;
while (top--) print_char(q[top]);
}
}

void print_ll(ll x) {
static char q[20];
if (!x) print_char('0');
else {
if (x < 0) print_char('-'), x = -x;
int top = 0;
while (x) q[top++] = x % 10 + '0', x /= 10;
while (top--) print_char(q[top]);
}
}

struct flusher_t {
~flusher_t() {
flush();
}
} flusher;

};
using namespace io;

const int N = 3e5 + 10;
const int M = 5e4 + 10;
const double eps = 1e-6;
const double PI = acos(-1);

typedef complex<double> Complex;
typedef vector<Complex> Poly;

Complex w[2][N];

void init() {
for (int i = 1; i < (1 << 18); i <<= 1) {
w[0][i] = w[1][i] = Complex(1, 0);
Complex wn(cos(PI / i), sin(PI / i));
for (int j = 1; j < i; j++)
w[1][i + j] = w[1][i + j - 1] * wn;
wn = Complex(cos(PI / i), -sin(PI / i));
for (int j = 1; j < i; j++)
w[0][i + j] = w[0][i + j - 1] * wn;
}
}

void transform(Complex *t, int len, int typ) {
for (int i = 0, j = 0, k; j < len; j++) {
if (i > j) swap(t[i], t[j]);
for (k = (len >> 1); k & i; k >>= 1) i ^= k;
i ^= k;
}
for (int i = 1; i < len; i <<= 1) {
for (int j = 0; j < len; j += (i << 1)) {
for (int k = 0; k < i; k++) {
Complex x = t[j + k], y = w[typ][i + k] * t[j + k + i];
t[j + k] = x + y;
t[j + k + i] = x - y;
}
}
}
if (typ) return;
for (int i = 0; i < len; i++)
t[i] = Complex(t[i].real() / (double) len, t[i].imag());
}

bool equ0(double x) {
return fabs(x) < eps;
}

Poly mul(const Poly a, const Poly b) {
static Poly cura, curb;
cura = a, curb = b;
int len = 1 << (int) ceil(log2(cura.size() + curb.size() - 1));
cura.resize(len), curb.resize(len);
transform(&cura[0], len, 1);
transform(&curb[0], len, 1);
for (int i = 0; i < len; i++)
cura[i] *= curb[i];
transform(&cura[0], len, 0);
return cura;
}

int n, m, q, maxa, maxb;
int a[N], b[N];
int cnta[N], cntb[N];

void devide(int l, int r) {
if (l == r) return;
int mid = (l + r) >> 1;
devide(l, mid);
devide(mid + 1, r);
Poly x, y;
int sizl = mid - l + 1, sizr = r - mid;
x.resize(sizl);
y.resize(sizr);
for (int i = 0; i < sizl; i++)
x[i] = cnta[i + l];
for (int i = 0; i < sizr; i++)
y[i] = cntb[i + mid + 1];
x = mul(x, y);
for (int i = 0; i < (signed) x.size(); i++)
ansadd[i + l + mid + 1] += x[i];
}

devide(0, max(maxa, maxb));
}

void calcsub() {
static Poly x, y;
x.resize(maxb + maxa + 1);
y.resize(maxb + maxa + 1);
for (int i = 0; i <= maxb + maxa; i++)
x[i] = y[i] = 0;
for (int i = 0; i <= maxa; i++)
x[maxb + i] = cnta[i];
for (int i = 0; i <= maxb; i++)
y[maxb - i] = cntb[i];
x = mul(x, y);
for (int i = maxb * 2; i < (signed) x.size(); i++)
anssub[i - maxb * 2] = x[i];
}

void solve() {
maxa = maxb = 0;
for (int i = 1; i <= n; i++) {
maxa = max(maxa, a[i]);
}
for (int i = 1; i <= m; i++) {
maxb = max(maxb, b[i]);
}
calcsub();
while (q--) {
print_char('\n');
}
for (int i = 0; i <= maxa; i++)
cnta[i] = 0;
for (int i = 0; i <= maxb; i++)
cntb[i] = 0;
for (int i = 0; i <= maxa + maxb; i++)
}