結果

問題 No.206 数の積集合を求めるクエリ
ユーザー CinnamorollCinnamoroll
提出日時 2019-06-10 13:58:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 410 ms / 7,000 ms
コード長 7,307 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 172,688 KB
実行使用メモリ 47,648 KB
最終ジャッジ日時 2024-04-15 20:19:55
合計ジャッジ時間 7,923 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 8 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 12 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 12 ms
5,376 KB
testcase_15 AC 11 ms
5,376 KB
testcase_16 AC 12 ms
5,376 KB
testcase_17 AC 294 ms
47,520 KB
testcase_18 AC 285 ms
47,528 KB
testcase_19 AC 298 ms
47,524 KB
testcase_20 AC 288 ms
47,520 KB
testcase_21 AC 294 ms
47,524 KB
testcase_22 AC 286 ms
47,524 KB
testcase_23 AC 292 ms
47,524 KB
testcase_24 AC 409 ms
47,524 KB
testcase_25 AC 410 ms
47,400 KB
testcase_26 AC 394 ms
47,520 KB
testcase_27 AC 369 ms
47,520 KB
testcase_28 AC 404 ms
47,528 KB
testcase_29 AC 409 ms
47,524 KB
testcase_30 AC 405 ms
47,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1int<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);i--)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

typedef complex<double> C;
int fft_n;
vector<C> omega;

int mod_pow(int x, int y = MOD - 2) {
  int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % MOD;
    x = (x * x) % MOD;
    y >>= 1;
  }
  return res;
}

void init_fft(int n) {
  fft_n = n;
  omega.resize(n);
  double angle = 2 * M_PI / n;
  REP(i,n) {
    omega[i] = C(cos(i * angle), sin(i * angle));
  }
}

void fft(vector<C> & a) {
  int n = a.size();
  if (n == 1) return;
  int half = n >> 1;
  vector<C> even(half), odd(half);
  for (int i = 0, j = 0; i < n; i += 2, ++j) {
    even[j] = a[i];
    odd[j] = a[i+1];
  }
  fft(even); fft(odd);
  for (int i = 0, fact = fft_n / n; i < half; ++i) {
    C twiddle = odd[i] * omega[i * fact];
    a[i] = even[i] + twiddle;
    a[i + half] = even[i] - twiddle;
  }
}

vector<int> mul_fft(const vector<int> &a, const vector<int> &b) {
  vector<int> res;
  vector<C> fa(a.begin(), a.end()), fb(b.begin(), b.end());
  int n = 1;
  while (n < 2 * max (a.size(), b.size())) n <<= 1;
  fa.resize(n); fb.resize(n);
  init_fft(n);
  fft(fa); fft(fb);
  REP(i,n) fa[i] = conj(fa[i] * fb[i]);
  fft(fa);
  res.resize (n);
  REP(i,n) {
    res[i] = (int) (fa[i].real() / n + 0.5);
  }
  return res;
}
// vec hoge = mul_fft(a,b)で呼び出し
// hoge[i]はΣa[k]*b[i-k]
// a,bは1-indexedで取る(0があれば0に)

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int l,m,n;
  cin >> l >> m >> n;

  vector<int> a(2*n+1,0);
  REP(i,l){
    int x;
    cin >> x;
    a[x+n]++;
  }
  
  vector<int> b(2*n+1,0);
  REP(i,m){
    int x;
    cin >> x;
    b[n-x]++;
  }
  
  int q;
  cin >> q;

  vec ans = mul_fft(a,b);
  //REP(i,ans.size()) cout << ans[i] << endl;

  FOR(i,2*n,2*n+q) cout << ans[i] << endl;

  return 0;
}
0