結果

問題 No.206 数の積集合を求めるクエリ
ユーザー EmKjpEmKjp
提出日時 2015-05-08 23:47:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,250 bytes
コンパイル時間 2,876 ms
コンパイル使用メモリ 91,948 KB
実行使用メモリ 17,536 KB
最終ジャッジ日時 2023-09-19 09:00:17
合計ジャッジ時間 6,737 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 4 ms
4,388 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,388 KB
testcase_16 WA -
testcase_17 AC 165 ms
17,400 KB
testcase_18 AC 157 ms
16,912 KB
testcase_19 AC 164 ms
17,140 KB
testcase_20 AC 78 ms
11,744 KB
testcase_21 AC 156 ms
16,948 KB
testcase_22 AC 157 ms
16,924 KB
testcase_23 AC 167 ms
17,324 KB
testcase_24 AC 179 ms
17,536 KB
testcase_25 AC 176 ms
17,368 KB
testcase_26 AC 169 ms
16,820 KB
testcase_27 AC 161 ms
16,736 KB
testcase_28 AC 166 ms
17,124 KB
testcase_29 AC 164 ms
17,044 KB
testcase_30 AC 164 ms
16,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>

using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;


const long double PI = 4.0*atan(1.0);

typedef complex<double> Complex;
const Complex I(0, 1);

template<typename T>
void fft(int n, double theta, vector<T>& a) {
  for (int m = n; m >= 2; m >>= 1) {
    int mh = m >> 1;
    for (int i = 0; i < mh; i++) {
      Complex w = exp(i*theta*I);
      for (int j = i; j < n; j += m) {
        int k = j + mh;
        Complex x = a[j] - a[k];
        a[j] += a[k];
        a[k] = w * x;
      }
    }
    theta *= 2;
  }
  int i = 0;
  for (int j = 1; j < n - 1; j++) {
    for (int k = n >> 1; k > (i ^= k); k >>= 1);
    if (j < i) swap(a[i], a[j]);
  }
}

// result[i] = sum a[x] * b[y] where x + y == i
template<typename T>
vector<long long> comvolution(const vector<T> &a, const vector<T> &b){
    vector<long long> result;
    vector<Complex> fa(a.begin(), a.end());
    vector<Complex> fb(b.begin(), b.end());
    while(SZ(fa) && fa.back().real() == 0.0) fa.pop_back();
    while(SZ(fb) && fb.back().real() == 0.0) fb.pop_back();
    int n = 1;
    while(n < SZ(fa) + SZ(fb)) n <<= 1;
    fa.resize(n);
    fb.resize(n);
    fft(n, 2 * PI / n, fa);
    fft(n, 2 * PI / n, fb);
    FOR(i,n) fa[i] *= fb[i];
    fft(n, -2 * PI / n, fa);
    FOR(i,n) result.push_back(round(fa[i].real()/n));
    return result;
}


int main()
{
    int L,M,N;
    cin>>L>>M>>N;
    VI A(L);
    VI B(M);
    FOR(i,L) scanf("%d",&A[i]);
    FOR(i,M) scanf("%d",&B[i]);
    int Q;
    cin>>Q;
    VI AH(N + 1);
    VI BH(N + 1);
    FOR(i,L) AH[A[i]]++;
    FOR(i,M) BH[B[i]]++;
    reverse(ALL(BH));
    auto r = comvolution(AH, BH);
    FOR(i,Q){
        printf("%lld\n", r[i+N]);
    }
    return 0;
}
0