結果

問題 No.206 数の積集合を求めるクエリ
ユーザー risujirohrisujiroh
提出日時 2018-10-29 03:56:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 7,000 ms
コード長 1,630 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 173,464 KB
実行使用メモリ 14,700 KB
最終ジャッジ日時 2024-04-29 22:40:02
合計ジャッジ時間 4,823 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 90 ms
14,696 KB
testcase_18 AC 82 ms
14,568 KB
testcase_19 AC 92 ms
14,696 KB
testcase_20 AC 82 ms
14,700 KB
testcase_21 AC 85 ms
14,696 KB
testcase_22 AC 85 ms
14,696 KB
testcase_23 AC 91 ms
14,568 KB
testcase_24 AC 98 ms
14,700 KB
testcase_25 AC 95 ms
14,696 KB
testcase_26 AC 89 ms
14,696 KB
testcase_27 AC 85 ms
14,700 KB
testcase_28 AC 89 ms
14,696 KB
testcase_29 AC 90 ms
14,564 KB
testcase_30 AC 86 ms
14,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


using R = double;
using C = complex<R>;
constexpr R pi = acos((R) -1);

void dft(V<C>& a, R theta) {
  int n = a.size();
  int j = 0;
  for (int i = 1; i < n; ++i) {
    int k = n >> 1;
    while (j >= k) j -= k, k >>= 1;
    j += k;
    if (i < j) swap(a[i], a[j]);
  }
  for (int k = 1; k < n; k <<= 1) {
    V<C> xi(k);
    for (int i = 0; i < k; ++i) xi[i] = polar<R>(1, i * theta);
    for (int i = 0; i < n; ++i) if (~i & k) {
      j = i + k;
      tie(a[i], a[j]) = make_pair(a[i] + a[j] * xi[i & k - 1], a[i] - a[j] * xi[i & k - 1]);
    }
    theta /= 2;
  }
}

void convolution(V<C>& a, V<C>& b) {
  int n = a.size(), m = b.size();
  n = 1 << __lg(2 * (n + m - 1) - 1);
  a.resize(n), b.resize(n);
  dft(a, pi), dft(b, pi);
  for (int i = 0; i < n; ++i) a[i] *= b[i];
  dft(a, -pi);
  for (int i = 0; i < n; ++i) a[i] /= n;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int l, m, n; cin >> l >> m >> n;
  V<C> a(n), b(n);
  for (int i = 0; i < l; ++i) {
    int x; cin >> x, --x;
    a[n - 1 - x] = C(1);
  }
  for (int i = 0; i < m; ++i) {
    int x; cin >> x, --x;
    b[x] = C(1);
  }
  convolution(a, b);
  int q; cin >> q;
  for (int i = 0; i < q; ++i) cout << (int) (real(a[n - 1 - i]) + 0.5) << '\n';
}
0