結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | Pulmn |
提出日時 | 2018-07-20 11:21:50 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 285 ms / 7,000 ms |
コード長 | 1,770 bytes |
コンパイル時間 | 1,360 ms |
コンパイル使用メモリ | 151,896 KB |
実行使用メモリ | 9,684 KB |
最終ジャッジ日時 | 2023-08-27 00:15:06 |
合計ジャッジ時間 | 7,238 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 5 ms
4,380 KB |
testcase_07 | AC | 5 ms
4,376 KB |
testcase_08 | AC | 5 ms
4,380 KB |
testcase_09 | AC | 5 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 9 ms
4,380 KB |
testcase_13 | AC | 8 ms
4,376 KB |
testcase_14 | AC | 8 ms
4,376 KB |
testcase_15 | AC | 9 ms
4,376 KB |
testcase_16 | AC | 8 ms
4,380 KB |
testcase_17 | AC | 158 ms
9,396 KB |
testcase_18 | AC | 135 ms
9,344 KB |
testcase_19 | AC | 156 ms
9,456 KB |
testcase_20 | AC | 133 ms
9,684 KB |
testcase_21 | AC | 141 ms
9,456 KB |
testcase_22 | AC | 143 ms
9,384 KB |
testcase_23 | AC | 154 ms
9,344 KB |
testcase_24 | AC | 282 ms
9,396 KB |
testcase_25 | AC | 285 ms
9,536 KB |
testcase_26 | AC | 263 ms
9,348 KB |
testcase_27 | AC | 221 ms
9,344 KB |
testcase_28 | AC | 269 ms
9,336 KB |
testcase_29 | AC | 271 ms
9,540 KB |
testcase_30 | AC | 260 ms
9,480 KB |
ソースコード
#include <bits/stdc++.h> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=1e9+7; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; const ll p=924844033,r=5; ll Pow(ll n,ll m){ ll res=1; while(m>0){ if(m&1) (res*=n)%=p; (n*=n)%=p; m>>=1; } return res; } ll Inv(ll x){return Pow(x,p-2);} void ntt(vl& a,bool B){ int n=a.size(),h=0; while(1<<h<n) h++; for(int i=0;i<n;i++){ int j=0; for(int k=0;k<h;k++) if(i&1<<k) j+=1<<(h-k-1); if(i<j) swap(a[i],a[j]); } for(int i=1;i<n;i*=2){ ll w=Pow(r,(p-1)/(i*2)); if(B) w=Inv(w); for(int j=0;j<n;j+=i*2){ ll wn=1; for(int k=0;k<i;k++){ ll s=a[j+k],t=a[i+j+k]*wn%p; a[j+k]=(s+t)%p; a[i+j+k]=(s-t+p)%p; (wn*=w)%=p; } } } if(B){ ll v=Inv(n); for(int i=0;i<n;i++) (a[i]*=v)%=p; } } vl Conv(vl a,vl b){ int s=a.size()+b.size()-1,t=1; while(t<s) t*=2; a.resize(t); b.resize(t); ntt(a,0);ntt(b,0); for(int i=0;i<t;i++) (a[i]*=b[i])%=p; ntt(a,1); a.resize(s); return a; } int n,m,N,q; vl a,b; int main(){ cin>>n>>m>>N; a=b=vl(N); for(int i=0;i<n;i++){ int A; cin>>A; a[A-1]++; } for(int i=0;i<m;i++){ int A; cin>>A; b[N-A]++; } vl c=Conv(a,b); cin>>q; for(int i=N-1;i<N+q-1;i++) cout<<c[i]<<endl; }