結果

問題 No.206 数の積集合を求めるクエリ
ユーザー homesentinelhomesentinel
提出日時 2019-09-04 22:44:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 232 ms / 7,000 ms
コード長 3,618 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 120,296 KB
実行使用メモリ 14,184 KB
最終ジャッジ日時 2023-08-28 17:13:27
合計ジャッジ時間 6,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 7 ms
4,376 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 109 ms
14,016 KB
testcase_18 AC 98 ms
13,936 KB
testcase_19 AC 104 ms
14,012 KB
testcase_20 AC 97 ms
13,956 KB
testcase_21 AC 99 ms
14,184 KB
testcase_22 AC 101 ms
13,900 KB
testcase_23 AC 105 ms
13,936 KB
testcase_24 AC 232 ms
14,024 KB
testcase_25 AC 231 ms
13,988 KB
testcase_26 AC 222 ms
13,996 KB
testcase_27 AC 186 ms
13,996 KB
testcase_28 AC 221 ms
14,032 KB
testcase_29 AC 223 ms
14,092 KB
testcase_30 AC 225 ms
14,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
namespace FastFourierTransform {
    using C = complex<double>;

    void DiscreteFourierTransform(vector<C> &F, bool rev) {
        const int N = (int) F.size();
        const double PI = (rev ? -1 : 1) * acos(-1);
        for (int i = 0, j = 1; j + 1 < N; j++) {
            for (int k = N >> 1; k > (i ^= k); k >>= 1);
            if (i > j) swap(F[i], F[j]);
        }
        C w, s, t;
        for (int i = 1; i < N; i <<= 1) {
            for (int k = 0; k < i; k++) {
                w = polar(1.0, PI / i * k);
                for (int j = 0; j < N; j += i * 2) {
                    s = F[j + k];
                    t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(),
                          F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
                    F[j + k] = s + t, F[j + k + i] = s - t;
                }
            }
        }
        if (rev) for (int i = 0; i < N; i++) F[i] /= N;
    }

    vector<long long> Multiply(const vector<int> &A, const vector<int> &B) {
        int sz = 1;
        while (sz < A.size() + B.size() - 1) sz <<= 1;
        vector<C> F(sz), G(sz);
        for (int i = 0; i < A.size(); i++) F[i] = A[i];
        for (int i = 0; i < B.size(); i++) G[i] = B[i];
        DiscreteFourierTransform(F, false);
        DiscreteFourierTransform(G, false);
        for (int i = 0; i < sz; i++) F[i] *= G[i];
        DiscreteFourierTransform(F, true);
        vector<long long> X(A.size() + B.size() - 1);
        for (int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
        return (X);
    }
};

class Solve {
public:
    void solve() {
        Int L, M, N;
        cin >> L >> M >> N;
        vector<int> A(N);
        vector<int> B(N);
        for (int i = 0; i < L; ++i) {
            Int tmp;
            cin >> tmp;
            tmp--;
            A[tmp]++;
        }

        for (int i = 0; i < M; ++i) {
            Int tmp;
            cin >> tmp;
            tmp--;
            B[tmp]++;
        }

        Int Q;
        cin >> Q;
        reverse(all(B));

        auto C = FastFourierTransform::Multiply(A, B);
        for (int i = N - 1; i <= N + Q - 2; ++i) {
            cout << C[i] << endl;
        }


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}
0