結果

問題 No.206 数の積集合を求めるクエリ
ユーザー tempura_pptempura_pp
提出日時 2018-06-24 19:09:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 358 ms / 7,000 ms
コード長 1,747 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 95,236 KB
実行使用メモリ 36,748 KB
最終ジャッジ日時 2023-09-13 13:45:36
合計ジャッジ時間 7,047 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 10 ms
4,380 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 10 ms
4,380 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 11 ms
4,616 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 9 ms
4,604 KB
testcase_16 AC 10 ms
4,456 KB
testcase_17 AC 351 ms
35,856 KB
testcase_18 AC 317 ms
36,312 KB
testcase_19 AC 346 ms
36,036 KB
testcase_20 AC 323 ms
36,340 KB
testcase_21 AC 330 ms
36,432 KB
testcase_22 AC 328 ms
36,248 KB
testcase_23 AC 349 ms
36,028 KB
testcase_24 AC 358 ms
35,780 KB
testcase_25 AC 356 ms
36,072 KB
testcase_26 AC 332 ms
35,952 KB
testcase_27 AC 325 ms
36,236 KB
testcase_28 AC 340 ms
36,748 KB
testcase_29 AC 344 ms
36,544 KB
testcase_30 AC 329 ms
36,056 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,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=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,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);
    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)<<"\n";
}
0