結果
| 問題 |
No.206 数の積集合を求めるクエリ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-17 21:17:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 141 ms / 7,000 ms |
| コード長 | 4,071 bytes |
| コンパイル時間 | 2,160 ms |
| コンパイル使用メモリ | 204,212 KB |
| 最終ジャッジ日時 | 2025-01-18 21:52:17 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#line 1 "compro_library/template/template.cpp"
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return 1;
}
return 0;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << '(' << p.first << ',' << p.second << ')';
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
for(int i = 0; i < (int)v.size(); i++) {
if(i) { os << ','; }
os << v[i];
}
os << '}';
return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
cerr << " " << x;
debugg(args...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
struct Setup {
Setup() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __Setup;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//-------------------------------------
#line 1 "compro_library/math/fft.hpp"
namespace FFT {
using D = double;
struct C {
D x, y;
C() : x(0), y(0) {}
C(D x, D y) : x(x), y(y) {}
C(complex<D> c) : x(c.real()), y(c.imag()) {}
inline C operator+(const C &c) const { return C(x + c.x, y + c.y); }
inline C operator-(const C &c) const { return C(x - c.x, y - c.y); }
inline C operator*(const C &c) const {
return C(x * c.x - y * c.y, x * c.y + y * c.x);
}
};
const D PI = acosl(-1);
vector<C> fft(vector<C> a, bool inv = false) {
int n = int(a.size());
int h = 0;
for(int i = 0; 1 << i < n; i++) h++;
for(int i = 0; i < n; i++) {
int j = 0;
for(int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
if(i < j) swap(a[i], a[j]);
}
for(int b = 1; b < n; b *= 2) {
for(int j = 0; j < b; j++) {
C w = C(polar<D>(1, (2 * PI) / (2 * b) * j * (inv ? 1 : -1)));
for(int k = 0; k < n; k += 2 * b) {
C s = a[j + k], t = a[j + k + b] * w;
a[j + k] = s + t, a[j + k + b] = s - t;
}
}
}
if(inv) {
for(int i = 0; i < n; i++) a[i] = C(a[i].x / n, a[i].y / n);
}
return a;
}
vector<C> fft(vector<D> a, bool inv = false) {
vector<C> A(a.size());
for(int i = 0; i < int(a.size()); i++) A[i] = C(a[i], 0);
return fft(A, inv);
}
vector<D> conv(vector<D> a, vector<D> b) {
int s = int(a.size() + b.size()) - 1;
int t = 1;
while(t < s) t *= 2;
a.resize(t), b.resize(t);
vector<C> A = fft(a), B = fft(b);
for(int i = 0; i < t; i++) A[i] = A[i] * B[i];
A = fft(A, true);
a.resize(s);
for(int i = 0; i < s; i++) a[i] = A[i].x;
return a;
}
} // namespace FFT
#line 3 "t.cpp"
int L, M, N, Q;
vector<double> A, B;
int main() {
cin >> L >> M >> N;
A.resize(N+1); B.resize(N+1);
REP(i, L) {
int x; cin >> x;
A[x] += 1.0;
}
REP(i, M) {
int x; cin >> x;
B[N - x] += 1.0;
}
auto C = FFT::conv(A, B);
cin >> Q;
REP(v, Q) {
ll res = ll(C[N + v] + 0.5);
cout << res << "\n";
}
}