結果

問題 No.206 数の積集合を求めるクエリ
ユーザー 👑 NachiaNachia
提出日時 2020-10-06 21:57:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 7,000 ms
コード長 1,489 bytes
コンパイル時間 1,716 ms
コンパイル使用メモリ 169,680 KB
実行使用メモリ 14,432 KB
最終ジャッジ日時 2023-09-27 08:57:13
合計ジャッジ時間 6,601 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 4 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 136 ms
14,212 KB
testcase_18 AC 111 ms
14,216 KB
testcase_19 AC 133 ms
14,324 KB
testcase_20 AC 109 ms
14,116 KB
testcase_21 AC 115 ms
14,432 KB
testcase_22 AC 114 ms
14,176 KB
testcase_23 AC 135 ms
14,308 KB
testcase_24 AC 271 ms
14,268 KB
testcase_25 AC 261 ms
14,180 KB
testcase_26 AC 242 ms
14,232 KB
testcase_27 AC 196 ms
14,120 KB
testcase_28 AC 246 ms
14,148 KB
testcase_29 AC 244 ms
14,120 KB
testcase_30 AC 235 ms
14,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

using C = complex<double>;
double pi = acos(-1.0);

void FFT(vector<C> & A, bool inv) {
    int N = A.size();
    for (int i = 0, j = 0; j < N; j++) {
        if (i < j) swap(A[i], A[j]);
        for (int k = N >> 1; k > (i ^= k); k >>= 1);
    }
    for (int i = 1; i < N; i <<= 1) {
        C q = C(cos(pi / i), sin(pi / i) * (inv ? 1.0 : -1.0));
        C qj = C(1.0, 0.0);
        rep(j, i) {
            for (int k = j; k < N; k += i * 2) {
                C l = A[k], r = A[k + i] * qj;
                A[k] = l + r;
                A[k + i] = l - r;
            }
            qj *= q;
        }
    }
    if (inv) rep(i, N) A[i] /= N;
}

vector<C> CONV(const vector<C> & A, const vector<C> & B) {
    int Z = 1; while (Z < A.size() + B.size()) Z <<= 1;
    vector<C> Ax(Z), Bx(Z);
    rep(i, Z) Ax[i] = Bx[i] = 0;
    rep(i, A.size()) Ax[i] = A[i];
    rep(i, B.size()) Bx[i] = B[i];
    FFT(Ax, false);
    FFT(Bx, false);
    rep(i, Z) Ax[i] *= Bx[i];
    FFT(Ax, true);
    return move(Ax);
}

int main() {
    int L, M, N; cin >> L >> M >> N;
    vector<C> A(N, C(0., 0.)), B(N, C(0., 0.));
    rep(i, L) { int a; cin >> a; A[a - 1] += C(1., 0.); }
    rep(i, M) { int a; cin >> a; B[N - a] += C(1., 0.); }
    vector<C> X = CONV(A, B);
    int Q; cin >> Q;
    rep(i, Q) cout << int(X[N + i - 1].real() + 0.5) << endl;
    return 0;
}
0