結果

問題 No.206 数の積集合を求めるクエリ
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-05-20 11:20:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 7,000 ms
コード長 2,249 bytes
コンパイル時間 3,338 ms
コンパイル使用メモリ 174,184 KB
実行使用メモリ 20,756 KB
最終ジャッジ日時 2023-10-19 04:09:03
合計ジャッジ時間 5,760 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 131 ms
20,756 KB
testcase_18 AC 122 ms
20,364 KB
testcase_19 AC 127 ms
20,680 KB
testcase_20 AC 131 ms
20,368 KB
testcase_21 AC 123 ms
20,464 KB
testcase_22 AC 123 ms
20,464 KB
testcase_23 AC 130 ms
20,696 KB
testcase_24 AC 140 ms
20,756 KB
testcase_25 AC 139 ms
20,668 KB
testcase_26 AC 130 ms
20,364 KB
testcase_27 AC 126 ms
20,288 KB
testcase_28 AC 131 ms
20,464 KB
testcase_29 AC 134 ms
20,464 KB
testcase_30 AC 130 ms
20,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
const double PI = acos(-1.0);
typedef complex<double> P;
void fft(vector<P> &a, int isRev = 0) { // 配列aのサイズは2の累乗じゃないとダメ
    const P I(0.0, 1.0); int n = a.size(); double theta = 2 * PI / n; if (isRev) theta = -2 * PI / n;
    for (int m = n; m >= 2; m >>= 1) { int mh = m >> 1; rep(i, 0, mh) { P w = exp(i*theta*I);
    for (int j = i; j < n; j += m) { int k = j + mh; P x = a[j] - a[k]; a[j] += a[k]; a[k] = w * x; } }
        theta *= 2; } int i = 0;
    rep(j, 1, n - 1) { for (int k = n >> 1; k >(i ^= k); k >>= 1); if (j < i) swap(a[i], a[j]); }
    if (isRev) rep(i, 0, n) a[i] /= n; }
vector<int> convolution(vector<int> a, vector<int> b) {
    int n = a.size(), m = 1; while (m < n) m *= 2;
    vector<P> A(m), B(m); rep(i, 0, n) { A[i] = P(a[i], 0); B[i] = P(b[i], 0); } fft(A); fft(B);
    vector<P> C(m); rep(i, 0, m) C[i] = A[i] * B[i]; fft(C, 1);
    vector<int> res; rep(i, 0, n) res.push_back(int(real(C[i]) + 0.3)); return res; }
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int L, M, N, A[101010], B[101010], Q;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> L >> M >> N;
    rep(i, 0, L) cin >> A[i];
    rep(i, 0, M) cin >> B[i];
    cin >> Q;

    vector<int> a(N * 2 + 2), b(N * 2 + 2);
    rep(i, 0, L) a[A[i]] = 1;
    rep(i, 0, M) b[N - B[i]] = 1;

    auto ans = convolution(a, b);
    rep(i, N, N + Q) printf("%d\n", ans[i]);
}
0