結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | outline |
提出日時 | 2021-02-09 21:21:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 215 ms / 7,000 ms |
コード長 | 3,394 bytes |
コンパイル時間 | 1,454 ms |
コンパイル使用メモリ | 142,760 KB |
実行使用メモリ | 28,012 KB |
最終ジャッジ日時 | 2024-07-07 03:22:57 |
合計ジャッジ時間 | 5,705 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 7 ms
6,944 KB |
testcase_07 | AC | 7 ms
6,940 KB |
testcase_08 | AC | 7 ms
6,940 KB |
testcase_09 | AC | 8 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 7 ms
6,940 KB |
testcase_13 | AC | 7 ms
6,944 KB |
testcase_14 | AC | 7 ms
6,940 KB |
testcase_15 | AC | 7 ms
6,940 KB |
testcase_16 | AC | 7 ms
6,940 KB |
testcase_17 | AC | 204 ms
27,932 KB |
testcase_18 | AC | 198 ms
28,012 KB |
testcase_19 | AC | 201 ms
27,908 KB |
testcase_20 | AC | 198 ms
27,880 KB |
testcase_21 | AC | 196 ms
27,876 KB |
testcase_22 | AC | 193 ms
27,848 KB |
testcase_23 | AC | 202 ms
27,884 KB |
testcase_24 | AC | 215 ms
27,880 KB |
testcase_25 | AC | 215 ms
27,948 KB |
testcase_26 | AC | 199 ms
27,784 KB |
testcase_27 | AC | 196 ms
27,880 KB |
testcase_28 | AC | 193 ms
28,008 KB |
testcase_29 | AC | 197 ms
27,884 KB |
testcase_30 | AC | 197 ms
27,960 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); struct Complex { double real, imag; Complex(double r = 0, double i = 0) : real(r), imag(i) {} inline Complex& operator=(const Complex& c){ real = c.real; imag = c.imag; return *this; } }; inline Complex operator+(const Complex& x, const Complex& y){ return {x.real + y.real, x.imag + y.imag}; } inline Complex operator-(const Complex& x, const Complex& y){ return {x.real - y.real, x.imag - y.real}; } inline Complex operator*(const Complex& x, const Complex& y){ return {x.real * y.real - x.imag * y.imag, x.real * y.imag + x.imag * y.real}; } inline Complex operator*(const Complex& x, double a){ return {x.real * a, x.imag * a}; } inline Complex operator/(const Complex& x, double a){ return {x.real / a, x.imag / a}; } 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<Complex> inv_dft(vector<Complex>& a, int n){ a = dft(a, n, -1); for(int i = 0; i < n; ++i) a[i] = a[i] / n; 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]; } f = inv_dft(f, 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; }