結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | outline |
提出日時 | 2021-02-10 01:45:04 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 275 ms / 7,000 ms |
コード長 | 2,573 bytes |
コンパイル時間 | 1,593 ms |
コンパイル使用メモリ | 141,364 KB |
実行使用メモリ | 35,320 KB |
最終ジャッジ日時 | 2023-09-21 13:02:25 |
合計ジャッジ時間 | 6,969 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 8 ms
4,432 KB |
testcase_07 | AC | 8 ms
4,376 KB |
testcase_08 | AC | 8 ms
4,380 KB |
testcase_09 | AC | 8 ms
4,472 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 8 ms
4,380 KB |
testcase_13 | AC | 9 ms
4,552 KB |
testcase_14 | AC | 8 ms
4,380 KB |
testcase_15 | AC | 8 ms
4,396 KB |
testcase_16 | AC | 8 ms
4,380 KB |
testcase_17 | AC | 268 ms
35,128 KB |
testcase_18 | AC | 259 ms
35,140 KB |
testcase_19 | AC | 264 ms
35,152 KB |
testcase_20 | AC | 256 ms
34,996 KB |
testcase_21 | AC | 258 ms
34,932 KB |
testcase_22 | AC | 255 ms
34,948 KB |
testcase_23 | AC | 266 ms
35,244 KB |
testcase_24 | AC | 275 ms
35,320 KB |
testcase_25 | AC | 272 ms
35,152 KB |
testcase_26 | AC | 268 ms
35,072 KB |
testcase_27 | AC | 260 ms
34,948 KB |
testcase_28 | AC | 269 ms
35,068 KB |
testcase_29 | AC | 261 ms
35,016 KB |
testcase_30 | AC | 261 ms
34,952 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> #include <unordered_set> using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } const double pi = acos(-1); using Complex = complex<double>; vector<Complex> dft(vector<Complex> a, int n, int sgn = 1){ if(n == 1) return a; int m = n / 2; vector<Complex> f(m), g(m); for(int i = 0; i < m; ++i){ f[i] = a[2 * i]; g[i] = a[2 * i + 1]; } // divide and conquer f = dft(f, m, sgn); g = dft(g, m, sgn); // zeta : nth root of 1 Complex zeta(cos(2.0 * pi / n), sin(2.0 * pi / n) * sgn); Complex x = 1; for(int i = 0; i < m; ++i){ a[i] = f[i] + x * g[i]; x = x * zeta; } for(int i = m; i < n; ++i){ a[i] = f[i - m] + x * g[i - m]; x = x * zeta; } return a; } vector<int64_t> multiply(vector<Complex> a, vector<Complex> b){ int sz = a.size() + b.size() - 1; int n = 1; while(n < sz) n <<= 1; a.resize(n); b.resize(n); a = dft(a, n); b = dft(b, n); vector<Complex> f(n); for(int i = 0; i < n; ++i){ f[i] = a[i] * b[i]; } // inverse dft f = dft(f, n, -1); for(int i = 0; i < n; ++i) f[i] /= n; vector<int64_t> res(n); for(int i = 0; i < n; ++i){ res[i] = llround(f[i].real()); } return res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int L, M, N, A, B, Q; cin >> L >> M >> N; vector<Complex> a(N), b(N); for(int i = 0; i < L; ++i){ cin >> A; a[A - 1] = Complex(1, 0); } for(int i = 0; i < M; ++i){ cin >> B; b[N - B] = Complex(1, 0); } auto c = multiply(a, b); cin >> Q; for(int i = 0; i < Q; ++i){ cout << c[N - 1 + i] << '\n'; } return 0; }