結果
| 問題 |
No.206 数の積集合を求めるクエリ
|
| コンテスト | |
| ユーザー |
tempura_pp
|
| 提出日時 | 2018-06-24 18:34:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,674 bytes |
| コンパイル時間 | 1,160 ms |
| コンパイル使用メモリ | 104,540 KB |
| 実行使用メモリ | 35,360 KB |
| 最終ジャッジ日時 | 2024-06-30 22:33:34 |
| 合計ジャッジ時間 | 7,817 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 2 |
| other | AC * 10 WA * 9 RE * 9 |
ソースコード
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;
typedef vector<complex<double>> poly;
const double pi=acos(-1);
poly dft(poly f,int n,bool rev){
if(n==1)return f;
poly g[2];
rep(i,2)g[i].resize(n/2);
rep(i,n/2){
g[0][i]=f[2*i];
g[1][i]=f[2*i+1];
}
g[0]=dft(g[0],n/2,rev);
g[1]=dft(g[1],n/2,rev);
complex<double> zeta=complex<double>(cos(2*pi/n),sin(2*pi/n));
if(rev)zeta=1.0/zeta;
complex<double> ret=1;
rep(i,n/2){
f[i]=g[0][i]+ret*g[1][i];
ret*=zeta;
}
rep(i,n/2){
f[i+n/2]=g[0][i]+ret*g[1][i];
ret*=zeta;
}
return f;
}
poly fft(poly g,poly h){
poly f;
int m=(int)g.size()+h.size()+1;
int sz=1;
while(sz<m)sz*=2;
f.resize(sz,0);
g.resize(sz,0);
h.resize(sz,0);
g=dft(g,sz,0);
h=dft(h,sz,0);
rep(i,sz)f[i]=g[i]*h[i];
f=dft(f,sz,1);
rep(i,sz)f[i]/=sz;
return f;
}
int main(){
int l,m,n;
cin>>l>>m>>n;
poly a,b;
a.resize(n);
b.resize(n);
rep(i,l){
int x;
cin>>x;
a[x]=1;
}
rep(i,m){
int x;
cin>>x;
b[n-x]=1;
}
poly c=fft(a,b);
int q;cin>>q;
rep(i,q)cout<<(int)(c[n+i].real()+0.5)<<"\n";
}
tempura_pp