結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | mdj982 |
提出日時 | 2018-09-26 17:20:14 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,710 bytes |
コンパイル時間 | 1,015 ms |
コンパイル使用メモリ | 113,588 KB |
実行使用メモリ | 32,200 KB |
最終ジャッジ日時 | 2024-10-11 06:09:27 |
合計ジャッジ時間 | 5,928 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 8 ms
6,820 KB |
testcase_13 | WA | - |
testcase_14 | AC | 8 ms
6,816 KB |
testcase_15 | AC | 9 ms
6,816 KB |
testcase_16 | AC | 8 ms
6,816 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 260 ms
32,028 KB |
testcase_25 | AC | 254 ms
31,948 KB |
testcase_26 | AC | 251 ms
31,880 KB |
testcase_27 | WA | - |
testcase_28 | AC | 249 ms
31,960 KB |
testcase_29 | AC | 244 ms
32,096 KB |
testcase_30 | AC | 246 ms
31,968 KB |
ソースコード
#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); Loopr(i, N) { cout << rndf(c[i].real()) << endl; } }