結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | siro53 |
提出日時 | 2023-09-26 00:31:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,682 bytes |
コンパイル時間 | 2,191 ms |
コンパイル使用メモリ | 207,492 KB |
実行使用メモリ | 26,112 KB |
最終ジャッジ日時 | 2024-07-18 19:53:13 |
合計ジャッジ時間 | 22,068 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 28 ms
5,376 KB |
testcase_07 | AC | 31 ms
5,376 KB |
testcase_08 | AC | 32 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 1,325 ms
25,856 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 1,308 ms
25,856 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
ソースコード
#line 1 "combined.cpp" #pragma region Macros #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; } #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 OVERLOAD3(_1, _2, _3, name, ...) name #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define REP1(i, n) for(int i = 0; i < int(n); i++) #define REP2(i, a, b) for(int i = (a); i < int(b); i++) #define REP(...) OVERLOAD3(__VA_ARGS__, REP2, REP1)(__VA_ARGS__) #define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end()) #define REVERSE(v) reverse(ALL(v)) #define SZ(v) ((int)(v).size()) const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; constexpr int MOD2 = 998244353; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; void Case(int i) { cout << "Case #" << i << ": "; } int popcount(int x) { return __builtin_popcount(x); } ll popcount(ll x) { return __builtin_popcountll(x); } #pragma endregion Macros #line 2 "/Users/siro53/kyo-pro/compro_library/math/convolution/convolution.hpp" #line 7 "/Users/siro53/kyo-pro/compro_library/math/convolution/convolution.hpp" namespace fft { template <typename D> struct Complex { D x, y; Complex(): x(0), y(0) {}; Complex(D x, D y) : x(x), y(y) {} Complex &operator+=(const Complex &c) { x += c.x; y += c.y; return (*this); } Complex &operator-=(const Complex &c) { x -= c.x; y -= c.y; return (*this); } Complex &operator*=(const Complex &c) { D nx = x * c.x - y * c.y; D ny = x * c.y + y * c.x; x = nx, y = ny; return (*this); } Complex &operator/=(const Complex& c) { // (a + bi) / (c + di) // (a + bi)(c - di) / (c^2 + d^2) // (ac + bd) + (bc - ad)i / (c^2 + d^2) D nx = (x * c.x + y * c.y) / (c.x * c.x + c.y * c.y); D ny = (y * c.x - x * c.y) / (c.x * c.x + c.y * c.y); x = nx, y = ny; return (*this); } Complex operator-() const { return Complex(-x, -y); } Complex operator+(const Complex &c) const { return Complex(*this) += c; } Complex operator-(const Complex &c) const { return Complex(*this) -= c; } Complex operator*(const Complex &c) const { return Complex(*this) *= c; } Complex operator/(const Complex &c) const { return Complex(*this) /= c; } }; template<typename D> constexpr const D PI = std::acos(D(-1)); template<typename D> inline Complex<D> omega(int k, int n) { return Complex<D>(std::cos(D(k) * 2 * PI<D> / n), std::sin(D(k) * 2 * PI<D> / n)); } inline int revbit(int mask, int bitlen) { int res = 0; while(bitlen--) { res = (res << 1) | (mask & 1); mask >>= 1; } return res; } template<typename D> void fft(std::vector<Complex<D>>& a, int bitlen) { int n = (int)a.size(); int len = n; while(len > 1) { for(int i = 0; i < n; i += len) { int t = len >> 1; for(int j = 0; j < t; j++) { int p = i + j; auto l = a[p]; auto r = a[p + t]; a[p] = l + r; a[p + t] = (l - r) * omega<D>(j, len); } } len >>= 1; } for(int i = 0; i < n; i++) { int j = revbit(i, bitlen); if(i < j) std::swap(a[i], a[j]); } } template<typename D> void ifft(std::vector<Complex<D>>& a, int bitlen) { int n = (int)a.size(); for(int i = 0; i < n; i++) { int j = revbit(i, bitlen); if(i < j) std::swap(a[i], a[j]); } int len = 2; while(len <= n) { for(int i = 0; i < n; i += len) { int t = len >> 1; for(int j = 0; j < t; j++) { int p = i + j; auto l = a[p]; auto r = a[p + t] * omega<D>(-j, len); a[p] = l + r; a[p + t] = l - r; } } len <<= 1; } for(int i = 0; i < n; i++) a[i] /= Complex<D>(n, 0); } template<typename D> std::vector<D> convolution(const std::vector<D>& a, const std::vector<D>& b) { int m = (int)a.size() + (int)b.size() - 1; int n = 1, bitlen = 0; while(n < m) { n <<= 1; bitlen++; } std::vector<Complex<D>> A(n), B(n); for(int i = 0; i < (int)a.size(); i++) A[i] = Complex<D>(a[i], 0); for(int i = 0; i < (int)b.size(); i++) B[i] = Complex<D>(b[i], 0); fft<D>(A, bitlen); fft<D>(B, bitlen); for(int i = 0; i < n; i++) A[i] *= B[i]; ifft<D>(A, bitlen); std::vector<D> res(m); for(int i = 0; i < m; i++) res[i] = A[i].x; return res; } }; // namespace fft #line 78 "combined.cpp" int main() { int L, M, N; cin >> L >> M >> N; vector<long double> fa(N+1, 0), fb(N+1, 0); REP(i, L) { int a; cin >> a; fa[a] += 1; } REP(i, M) { int b; cin >> b; fb[N - b] += 1; } auto c = fft::convolution<long double>(fa, fb); int Q; cin >> Q; REP(v, Q) cout << (ll)c[N + v] << '\n'; }