結果

問題 No.206 数の積集合を求めるクエリ
ユーザー tempura_pptempura_pp
提出日時 2018-06-24 18:24:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 486 ms / 7,000 ms
コード長 2,160 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 96,364 KB
実行使用メモリ 36,472 KB
最終ジャッジ日時 2023-09-13 13:44:41
合計ジャッジ時間 8,042 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 10 ms
4,384 KB
testcase_07 AC 9 ms
4,380 KB
testcase_08 AC 10 ms
4,564 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 15 ms
4,380 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 13 ms
4,388 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 14 ms
4,416 KB
testcase_17 AC 354 ms
36,324 KB
testcase_18 AC 328 ms
35,896 KB
testcase_19 AC 352 ms
36,368 KB
testcase_20 AC 329 ms
36,068 KB
testcase_21 AC 335 ms
36,048 KB
testcase_22 AC 334 ms
36,188 KB
testcase_23 AC 354 ms
36,472 KB
testcase_24 AC 486 ms
36,176 KB
testcase_25 AC 473 ms
35,848 KB
testcase_26 AC 462 ms
36,280 KB
testcase_27 AC 417 ms
36,152 KB
testcase_28 AC 465 ms
35,956 KB
testcase_29 AC 465 ms
36,460 KB
testcase_30 AC 453 ms
36,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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){
    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);
    g[1]=dft(g[1],n/2);
    complex<double> zeta=complex<double>(cos(2*pi/n),sin(2*pi/n));
    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;
    return f;
}

poly rdft(poly f,int n){
    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]=rdft(g[0],n/2);
    g[1]=rdft(g[1],n/2);
    complex<double> zeta=complex<double>(cos(2*pi/n),-sin(2*pi/n));
    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);
    h=dft(h,sz);
    rep(i,sz)f[i]=g[i]*h[i];
    f=rdft(f,sz);
    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);
    a.push_back(0);
    b.push_back(0);
    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)<<endl;
}
0