結果

問題 No.206 数の積集合を求めるクエリ
ユーザー tempura_pptempura_pp
提出日時 2018-06-27 00:48:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 146 ms / 7,000 ms
コード長 1,692 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 94,052 KB
実行使用メモリ 23,016 KB
最終ジャッジ日時 2023-09-13 14:16:56
合計ジャッジ時間 4,795 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 138 ms
22,836 KB
testcase_18 AC 110 ms
23,016 KB
testcase_19 AC 134 ms
22,824 KB
testcase_20 AC 111 ms
22,760 KB
testcase_21 AC 117 ms
22,660 KB
testcase_22 AC 117 ms
22,820 KB
testcase_23 AC 133 ms
22,716 KB
testcase_24 AC 146 ms
23,008 KB
testcase_25 AC 138 ms
22,724 KB
testcase_26 AC 120 ms
22,824 KB
testcase_27 AC 112 ms
22,672 KB
testcase_28 AC 128 ms
22,760 KB
testcase_29 AC 125 ms
22,712 KB
testcase_30 AC 116 ms
22,664 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 rev){
    int n=f.size();
   int j=0;
   REP(i,1,n-1){
       for(int k=n/2;k>(j^=k);k>>=1);
       if(i<j)swap(f[i],f[j]);
   }
   for(int i=1;i<n;i<<=1){
       complex<double>zeta=complex<double>(cos(pi/i),sin(pi/i)*rev);
       for(int j=0;j<n;j+=2*i){
           complex<double> ret=1;
           rep(k,i){
               complex<double> s=f[j+k];
               complex<double> t=f[j+k+i];
               f[j+k]=s+t*ret;
               f[j+k+i]=s-t*ret;
               ret*=zeta;
           }
       }
   }
   if(rev==-1)rep(i,n)f[i]/=n;
   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,1);
   h=dft(h,1);
   rep(i,sz)f[i]=g[i]*h[i];
   f=dft(f,-1);
   return f;
}
int main(){
    int l,m,n;
    cin>>l>>m>>n;
    poly a,b;
    a.resize(n+1);
    b.resize(n+1);
    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