結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | sntea |
提出日時 | 2017-02-17 02:14:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 323 ms / 7,000 ms |
コード長 | 4,277 bytes |
コンパイル時間 | 2,033 ms |
コンパイル使用メモリ | 179,752 KB |
実行使用メモリ | 50,044 KB |
最終ジャッジ日時 | 2024-06-09 13:10:52 |
合計ジャッジ時間 | 7,975 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,376 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 10 ms
5,376 KB |
testcase_07 | AC | 10 ms
5,376 KB |
testcase_08 | AC | 10 ms
5,376 KB |
testcase_09 | AC | 10 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 10 ms
5,376 KB |
testcase_13 | AC | 10 ms
5,376 KB |
testcase_14 | AC | 10 ms
5,376 KB |
testcase_15 | AC | 11 ms
5,376 KB |
testcase_16 | AC | 10 ms
5,376 KB |
testcase_17 | AC | 316 ms
49,940 KB |
testcase_18 | AC | 305 ms
49,400 KB |
testcase_19 | AC | 311 ms
49,788 KB |
testcase_20 | AC | 308 ms
49,608 KB |
testcase_21 | AC | 308 ms
49,528 KB |
testcase_22 | AC | 307 ms
49,628 KB |
testcase_23 | AC | 309 ms
49,816 KB |
testcase_24 | AC | 323 ms
49,972 KB |
testcase_25 | AC | 318 ms
49,868 KB |
testcase_26 | AC | 311 ms
49,556 KB |
testcase_27 | AC | 312 ms
50,044 KB |
testcase_28 | AC | 304 ms
49,692 KB |
testcase_29 | AC | 319 ms
49,580 KB |
testcase_30 | AC | 309 ms
49,512 KB |
ソースコード
#ifdef LOCAL111 #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #define _USE_MATH_DEFINES #include <bits/stdc++.h> const int INF = 1e9; using namespace std; template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; } #define endl '\n' #define ALL(a) (a).begin(),(a).end() #define SZ(a) int((a).size()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #ifdef LOCAL111 #define DEBUG(x) cout<<#x<<": "<<(x)<<endl template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;} #else #define DEBUG(x) true template<typename T> void dpite(T a, T b){ return; } #endif #define F first #define S second #define SNP string::npos #define WRC(hoge) cout << "Case #" << (hoge)+1 << ": " template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;} template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} typedef long long int LL; typedef unsigned long long ULL; typedef pair<int,int> P; void ios_init(){ //cout.setf(ios::fixed); //cout.precision(12); #ifdef LOCAL111 return; #endif ios::sync_with_stdio(false); cin.tie(0); } class Polynomial { private: typedef double Real; typedef complex<Real> Complex; typedef vector<Complex>::iterator iterator; typedef vector<Complex>::const_iterator const_iterator; vector<Complex> v; public: static const Real pi; Polynomial(int n){ v = vector<Complex>(n); } Polynomial(vector<Complex> x){ v = x; } Polynomial(){ } iterator begin(){return v.begin();} const_iterator begin() const {return v.begin();} iterator end(){return v.end();} const_iterator end() const {return v.end();} void push_back(Complex x) {v.push_back(x);} int size(){ return v.size(); } Complex& operator[](int i){ return v[i]; } const Complex& operator[](int i) const { return v[i]; } Polynomial dft(int n){ Polynomial res(n); for(int i = 0; i < (int)v.size(); ++i) { res[i] = v[i]; } for(int i = v.size(); i < n; ++i) { res[i] = 0; } function<Polynomial(Polynomial)> rec = [&](Polynomial p) -> Polynomial{ int n = p.size(); if(n == 1) return p; Polynomial f0(n/2); Polynomial f1(n/2); for(int i = 0; i < n; ++i) { if(i&1){ f1[i/2] = p[i]; }else{ f0[i/2] = p[i]; } } auto res0 = rec(f0); auto res1 = rec(f1); Complex theta = Complex(cos(2*pi/n),sin(2*pi/n)); Complex tmp = 1; Polynomial res(n); for(int i = 0; i < n; ++i) { int p = i; if(p >= n/2) p -= n/2; res[i] = res0[p]+res1[p]*tmp; tmp *= theta; } return res; }; res = rec(res); return res; } Polynomial inverse_dft(){ Polynomial res = *this; for(int i = 0; i < (int)res.size(); ++i) { res[i] = conj(res[i]); } int n = (int)v.size(); res = res.dft(n); for(int i = 0; i < (int)res.size(); ++i) { res[i] /= res.size(); } for(int i = 0; i < (int)res.size(); ++i) { res[i] = conj(res[i]); } return res; } Complex calc(Complex c){ Complex res = 0; Complex x = 1; for(int i = 0; i < (int)v.size(); ++i) { res += v[i]*x; x *= c; } return res; } Polynomial operator*(Polynomial y){ int m = y.size()+size(); int n = 1; while(n < m) { n <<= 1; } auto gg = dft(n); auto hh = y.dft(n); Polynomial res(n); for(int i = 0; i < n; ++i) { res[i] = gg[i]*hh[i]; } return res.inverse_dft(); } }; const Polynomial::Real Polynomial::pi(3.141592653589793238462643383279L); int main() { ios_init(); int l,m,n; while(cin >> l >> m >> n) { vector<int> a(l),b(m); REP(i,l){ cin >> a[i]; a[i]--; } REP(i,m){ cin >> b[i]; b[i]--; } int q; cin >> q; Polynomial g(n),h(n); dpite(ALL(g)); dpite(ALL(h)); REP(i,l){ g[a[i]] = 1; } REP(i,m){ h[n-1-b[i]] = 1; } auto f = g*h; dpite(ALL(f)); FOR(i,n-1,n-1+q){ int ans = round(f[i].real()); cout << ans << endl; } } return 0; }