結果

問題 No.206 数の積集合を求めるクエリ
ユーザー ArcArc
提出日時 2019-10-02 16:42:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 450 ms / 7,000 ms
コード長 2,634 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 108,256 KB
実行使用メモリ 47,540 KB
最終ジャッジ日時 2024-04-14 08:58:20
合計ジャッジ時間 8,286 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 9 ms
6,940 KB
testcase_07 AC 10 ms
6,940 KB
testcase_08 AC 10 ms
6,940 KB
testcase_09 AC 10 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 14 ms
6,944 KB
testcase_13 AC 13 ms
6,940 KB
testcase_14 AC 13 ms
6,940 KB
testcase_15 AC 13 ms
6,940 KB
testcase_16 AC 14 ms
6,944 KB
testcase_17 AC 319 ms
47,516 KB
testcase_18 AC 306 ms
47,476 KB
testcase_19 AC 311 ms
47,344 KB
testcase_20 AC 309 ms
47,436 KB
testcase_21 AC 314 ms
47,472 KB
testcase_22 AC 313 ms
47,540 KB
testcase_23 AC 316 ms
47,420 KB
testcase_24 AC 450 ms
47,392 KB
testcase_25 AC 443 ms
47,408 KB
testcase_26 AC 432 ms
47,460 KB
testcase_27 AC 398 ms
47,460 KB
testcase_28 AC 439 ms
47,292 KB
testcase_29 AC 441 ms
47,428 KB
testcase_30 AC 431 ms
47,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>
#include<complex>


//Copy from this line!

typedef std::complex<double> Complex;

std::vector<Complex> DFT(std::vector<Complex> func, int size, int sign){
  if(size==1) return func;

  std::vector<Complex> result(size);
  std::vector<Complex> func_a(size/2);
  std::vector<Complex> func_b(size/2);
  for(int i=0;i<size/2;i++){
    func_a[i]=func[2*i];
    func_b[i]=func[2*i+1];
  }
  func_a=DFT(func_a,size/2,sign);
  func_b=DFT(func_b,size/2,sign);

  Complex zeta(cos(2.0*M_PI/size),sin(2.0*M_PI/size)*sign);
  Complex zeta_pow(1);
  for(int i=0;i<size;i++){
    result[i]=func_a[i%(size/2)]+zeta_pow*func_b[i%(size/2)];
    zeta_pow*=zeta;
  }
  return result;
}

std::vector<Complex> InvDFT(std::vector<Complex> func, int size){
  std::vector<Complex> result=DFT(func, size, -1);
  for(int i=0;i<size;i++){
    result[i]/=size;
  }
  return result;
}

std::vector<Complex> MultyplyFunction(std::vector<Complex> func_f, std::vector<Complex> func_g){
  int min_size=func_f.size()+func_g.size()+1;
  int size=1;
  while(size<min_size){
    size*=2;
  }
  func_f.resize(size);
  func_g.resize(size);
  func_f=DFT(func_f,size,1);
  func_g=DFT(func_g,size,1);
  std::vector<Complex> func(size);
  for(int i=0;i<size;i++){
    func[i]=func_f[i]*func_g[i];
  }
  return InvDFT(func,size);


}

// int main(void){
//   int n;
//   cin>>n;
//   std::vector<std::complex<double>> a(n+1),b(n+1);
//   a[0]=std::complex<double>(0);
//   b[0]=std::complex<double>(0);
//   for(int i=1;i<=n;i++){
//     int x,y;
//     cin>>x>>y;
//     a[i]=std::complex<double>(x);
//     b[i]=std::complex<double>(y);
//   }
//   std::vector<std::complex<double>> c=MultyplyFunction(a,b);
//   for(int i=1;i<=2*n;i++){
//     cout<<lround(c[i].real())<<endl;
//   }
// }


using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int l,m,n;
  cin>>l>>m>>n;
  std::vector<Complex> a(n+1);
  std::vector<Complex> b(n+1);
  for(int i=0;i<l;i++){
    int v;
    cin>>v;
    a[v]=Complex(1);
  }
  for(int i=0;i<m;i++){
    int v;
    cin>>v;
    b[n-v]=Complex(1);
  }

  int q;
  cin>>q;
  std::vector<Complex> result=MultyplyFunction(a,b);

  for(int i=n;i<n+q;i++){
    cout<<lround(result[i].real())<<endl;
  }



  return 0;
}
0