結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | mdj982 |
提出日時 | 2018-09-26 17:25:02 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,764 bytes |
コンパイル時間 | 1,076 ms |
コンパイル使用メモリ | 112,884 KB |
実行使用メモリ | 32,324 KB |
最終ジャッジ日時 | 2024-10-11 06:09:33 |
合計ジャッジ時間 | 4,728 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 4 ms
6,816 KB |
testcase_07 | AC | 4 ms
6,816 KB |
testcase_08 | AC | 4 ms
6,820 KB |
testcase_09 | AC | 5 ms
6,816 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 125 ms
32,040 KB |
testcase_18 | AC | 113 ms
32,040 KB |
testcase_19 | AC | 120 ms
32,128 KB |
testcase_20 | AC | 110 ms
32,088 KB |
testcase_21 | AC | 109 ms
32,080 KB |
testcase_22 | AC | 118 ms
32,104 KB |
testcase_23 | AC | 120 ms
32,008 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
ソースコード
#include <iostream> #include <fstream> #include <iomanip> #include <climits> #include <limits> #include <algorithm> #include <array> #include <vector> #include <deque> #include <queue> #include <list> #include <stack> #include <string> #include <functional> #include <numeric> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <unordered_map> #include <random> #include <cmath> #include <complex> // #include "utiltime.hpp" using namespace std; typedef long long int ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef complex<double> cdouble; const int INFL = (int)1e9; const ll INFLL = (ll)1e18; const double INFD = numeric_limits<double>::infinity(); const double PI = 3.14159265358979323846; #define Loop(i, n) for(int i = 0; i < (int)n; i++) #define Loopll(i, n) for(ll i = 0; i < (ll)n; i++) #define Loop1(i, n) for(int i = 1; i <= (int)n; i++) #define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++) #define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--) #define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--) #define Loopr1(i, n) for(int i = (int)n; i >= 1; i--) #define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--) #define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++) #define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl; #define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; } #define quickio() ios::sync_with_stdio(false); cin.tie(0); #define bitmanip(m,val) static_cast<bitset<(int)m>>(val) ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); } ll floorsqrt(double x) { ll m = (ll)sqrt(x); return m + (m * m <= (ll)(x) ? 0 : -1); } ll ceilsqrt(double x) { ll m = (ll)sqrt(x); return m + ((ll)x <= m * m ? 0 : 1); } ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); } ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); } ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); } /*******************************************************/ namespace Fourier_transform { vector<cdouble> omegas, iomegas; inline int bit_reverse(int x, int digit) { int ret = digit ? x & 1 : 0; Loop(i, digit - 1) { ret <<= 1; x >>= 1; ret |= x & 1; } return ret; } inline void make_omegas(int n) { if (omegas.size() != n) { omegas.resize(n); Loop(i, n) omegas[i] = exp(cdouble({ 0, 2 * PI * i / n })); } } inline void make_iomegas(int n) { if (iomegas.size() != n) { iomegas.resize(n); Loop(i, n) iomegas[i] = exp(cdouble({ 0, -2 * PI * i / n })); } } // a.size() should be 2^digit vector<cdouble> FFT(const vector<cdouble> a) { int n = int(a.size()); int digit = int(rndf(log2(n))); vector<cdouble> ret = a; make_omegas(n); Loop(i, n) { int j = bit_reverse(i, digit); if (j > i) swap(ret[i], ret[j]); } Loop(i, digit) { int j = 0, m = 1 << i, mw = (digit - i - 1); Loop(group_id, n >> (i + 1)) { Loop(k, m) { cdouble x = ret[j] + omegas[k << mw] * ret[j + m]; cdouble y = ret[j] - omegas[k << mw] * ret[j + m]; ret[j] = x; ret[j + m] = y; ++j; } j += m; } } return ret; } // f.size() should be 2^digit vector<cdouble> IFFT(const vector<cdouble>& f) { int n = int(f.size()); int digit = int(rndf(log2(n))); vector<cdouble> ret = f; make_iomegas(n); Loopr(i, digit) { int j = 0, m = 1 << i, mw = (digit - i - 1); Loop(group_id, n >> (i + 1)) { Loop(k, m) { cdouble q = (ret[j] + ret[j + m]) * 0.5; cdouble r = (ret[j] - ret[j + m]) * 0.5 * iomegas[k << mw]; ret[j] = q; ret[j + m] = r; ++j; } j += m; } } Loop(i, n) { int j = bit_reverse(i, digit); if (j > i) swap(ret[i], ret[j]); } return ret; } // a.size() = b.size() should be 2^digit vector<cdouble> mul_convolution(const vector<cdouble> &a, const vector<cdouble> &b) { int n = int(a.size()); vector<cdouble> ret; vector<cdouble> g = FFT(a), h = FFT(b); Loop(i, n) g[i] *= h[i]; ret = IFFT(g); return ret; } int legal_size_of(int n) { int ret = 1 << (int)log2(n); if (ret < n) ret <<= 1; return ret; } } using namespace Fourier_transform; int main() { quickio(); int L, M, N; cin >> L >> M >> N; int n = legal_size_of(N * 2); vector<cdouble> a(n, 0), b(n, 0); Loop(i, L) { int abuf; cin >> abuf; abuf--; a[N - 1 - abuf] = 1; } Loop(i, M) { int bbuf; cin >> bbuf; bbuf--; b[bbuf] = 1; } vector<cdouble> c = mul_convolution(a, b); int q; cin >> q; reverse(c.begin(), c.begin() + N); Loopr(i, q) { cout << rndf(c[i].real()) << endl; } }