結果

問題 No.206 数の積集合を求めるクエリ
ユーザー siro53siro53
提出日時 2021-02-17 21:17:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 7,000 ms
コード長 4,071 bytes
コンパイル時間 4,881 ms
コンパイル使用メモリ 206,764 KB
実行使用メモリ 23,568 KB
最終ジャッジ日時 2023-10-12 07:23:27
合計ジャッジ時間 10,414 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 4 ms
4,352 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 4 ms
4,352 KB
testcase_09 AC 4 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 5 ms
4,356 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 5 ms
4,352 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 162 ms
23,328 KB
testcase_18 AC 152 ms
23,328 KB
testcase_19 AC 166 ms
23,408 KB
testcase_20 AC 152 ms
23,412 KB
testcase_21 AC 152 ms
23,340 KB
testcase_22 AC 160 ms
23,480 KB
testcase_23 AC 164 ms
23,408 KB
testcase_24 AC 169 ms
23,396 KB
testcase_25 AC 174 ms
23,444 KB
testcase_26 AC 171 ms
23,568 KB
testcase_27 AC 161 ms
23,388 KB
testcase_28 AC 170 ms
23,344 KB
testcase_29 AC 164 ms
23,456 KB
testcase_30 AC 159 ms
23,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "compro_library/template/template.cpp"
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------
#line 1 "compro_library/math/fft.hpp"
namespace FFT {
    using D = double;
    struct C {
        D x, y;
        C() : x(0), y(0) {}
        C(D x, D y) : x(x), y(y) {}
        C(complex<D> c) : x(c.real()), y(c.imag()) {}
        inline C operator+(const C &c) const { return C(x + c.x, y + c.y); }
        inline C operator-(const C &c) const { return C(x - c.x, y - c.y); }
        inline C operator*(const C &c) const {
            return C(x * c.x - y * c.y, x * c.y + y * c.x);
        }
    };
    const D PI = acosl(-1);

    vector<C> fft(vector<C> a, bool inv = false) {
        int n = int(a.size());
        int h = 0;
        for(int i = 0; 1 << i < n; i++) h++;
        for(int i = 0; i < n; i++) {
            int j = 0;
            for(int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
            if(i < j) swap(a[i], a[j]);
        }
        for(int b = 1; b < n; b *= 2) {
            for(int j = 0; j < b; j++) {
                C w = C(polar<D>(1, (2 * PI) / (2 * b) * j * (inv ? 1 : -1)));
                for(int k = 0; k < n; k += 2 * b) {
                    C s = a[j + k], t = a[j + k + b] * w;
                    a[j + k] = s + t, a[j + k + b] = s - t;
                }
            }
        }
        if(inv) {
            for(int i = 0; i < n; i++) a[i] = C(a[i].x / n, a[i].y / n);
        }
        return a;
    }
    vector<C> fft(vector<D> a, bool inv = false) {
        vector<C> A(a.size());
        for(int i = 0; i < int(a.size()); i++) A[i] = C(a[i], 0);
        return fft(A, inv);
    }
    vector<D> conv(vector<D> a, vector<D> b) {
        int s = int(a.size() + b.size()) - 1;
        int t = 1;
        while(t < s) t *= 2;
        a.resize(t), b.resize(t);
        vector<C> A = fft(a), B = fft(b);
        for(int i = 0; i < t; i++) A[i] = A[i] * B[i];
        A = fft(A, true);
        a.resize(s);
        for(int i = 0; i < s; i++) a[i] = A[i].x;
        return a;
    }
} // namespace FFT
#line 3 "t.cpp"

int L, M, N, Q;
vector<double> A, B;

int main() {
    cin >> L >> M >> N;

    A.resize(N+1); B.resize(N+1);
    REP(i, L) {
        int x; cin >> x;
        A[x] += 1.0;
    }
    REP(i, M) {
        int x; cin >> x;
        B[N - x] += 1.0;
    }

    auto C = FFT::conv(A, B);

    cin >> Q;
    REP(v, Q) {
        ll res = ll(C[N + v] + 0.5);
        cout << res << "\n";
    }
}
0