結果

問題 No.206 数の積集合を求めるクエリ
ユーザー kyunakyuna
提出日時 2020-02-06 15:04:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 259 ms / 7,000 ms
コード長 1,683 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 84,912 KB
実行使用メモリ 17,288 KB
最終ジャッジ日時 2023-10-25 22:33:40
合計ジャッジ時間 6,987 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
15,720 KB
testcase_01 AC 71 ms
15,724 KB
testcase_02 AC 71 ms
15,724 KB
testcase_03 AC 71 ms
15,720 KB
testcase_04 AC 71 ms
15,724 KB
testcase_05 AC 72 ms
15,724 KB
testcase_06 AC 72 ms
15,952 KB
testcase_07 AC 72 ms
15,952 KB
testcase_08 AC 72 ms
15,952 KB
testcase_09 AC 72 ms
15,952 KB
testcase_10 AC 72 ms
15,724 KB
testcase_11 AC 71 ms
15,724 KB
testcase_12 AC 77 ms
15,952 KB
testcase_13 AC 75 ms
15,952 KB
testcase_14 AC 76 ms
15,952 KB
testcase_15 AC 76 ms
15,952 KB
testcase_16 AC 76 ms
15,952 KB
testcase_17 AC 128 ms
17,288 KB
testcase_18 AC 101 ms
17,288 KB
testcase_19 AC 123 ms
17,288 KB
testcase_20 AC 100 ms
17,288 KB
testcase_21 AC 108 ms
17,288 KB
testcase_22 AC 107 ms
17,288 KB
testcase_23 AC 124 ms
17,288 KB
testcase_24 AC 259 ms
17,288 KB
testcase_25 AC 251 ms
17,288 KB
testcase_26 AC 231 ms
17,288 KB
testcase_27 AC 189 ms
17,288 KB
testcase_28 AC 236 ms
17,288 KB
testcase_29 AC 238 ms
17,288 KB
testcase_30 AC 228 ms
17,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#include <complex>
struct FFT {
    using Complex = complex<double>;
    const double PI = acos(-1);
    const int sz = 1 << 18;     // 262144
    void dft(vector<Complex> &x, bool inv) {
    	for (int i = sz >> 1; i >= 1; i >>= 1) {
    		Complex bs = polar(1.0, 2.0 * PI * i / sz * (inv ? -1 : 1)), w = 1;
            vector<Complex> y(sz);
    		for (int j = 0; 2 * j < sz; j += i) {
    			for (int k = 0; k < i; k++) {
    				y[j + k]             = x[2 * j + k] + w * x[2 * j + i + k];
    				y[j + k + (sz >> 1)] = x[2 * j + k] - w * x[2 * j + i + k];
    			}
    			w *= bs;
    		}
    		x = y;
    	}
    	if (inv) for (int i = 0; i < sz; i++) x[i] /= sz;
    }
    vector<long long> multiply(vector<long long> &a, vector<long long> &b) {
        vector<Complex> x(sz), y(sz);
        for (int i = 0; i < (int)a.size(); i++) x[i] = Complex(a[i], 0.0);
        for (int i = 0; i < (int)b.size(); i++) y[i] = Complex(b[i], 0.0);
        dft(x, false), dft(y, false);
        for (int i = 0; i < sz; i++) x[i] *= y[i];
        dft(x, true);
        vector<long long> c(sz);
        for (int i = 0; i < sz; i++) c[i] = (long long)(x[i].real() + 0.5);
        return c;
    }
} fft;

int main() {
    int L, M, N; cin >> L >> M >> N;
    vector<long long> as(N), bs(N);
    for (int i = 0; i < L; i++) {
        int a; cin >> a;
        as[a - 1] = 1;
    }
    for (int i = 0; i < M; i++) {
        int b; cin >> b;
        bs[N - b] = 1;
    }
    auto cs = fft.multiply(as, bs);
    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        cout << cs[N - 1 + i] << endl;
    }
	return 0;
}
0