結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | mdj982 |
提出日時 | 2018-09-26 02:51:59 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 242 ms / 7,000 ms |
コード長 | 4,316 bytes |
コンパイル時間 | 1,285 ms |
コンパイル使用メモリ | 112,964 KB |
実行使用メモリ | 15,744 KB |
最終ジャッジ日時 | 2024-10-07 23:21:08 |
合計ジャッジ時間 | 5,079 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 4 ms
5,248 KB |
testcase_07 | AC | 4 ms
5,248 KB |
testcase_08 | AC | 4 ms
5,248 KB |
testcase_09 | AC | 4 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 7 ms
5,248 KB |
testcase_13 | AC | 7 ms
5,248 KB |
testcase_14 | AC | 7 ms
5,248 KB |
testcase_15 | AC | 8 ms
5,248 KB |
testcase_16 | AC | 8 ms
5,248 KB |
testcase_17 | AC | 112 ms
15,616 KB |
testcase_18 | AC | 101 ms
15,744 KB |
testcase_19 | AC | 109 ms
15,664 KB |
testcase_20 | AC | 99 ms
15,616 KB |
testcase_21 | AC | 104 ms
15,616 KB |
testcase_22 | AC | 105 ms
15,616 KB |
testcase_23 | AC | 112 ms
15,684 KB |
testcase_24 | AC | 242 ms
15,744 KB |
testcase_25 | AC | 237 ms
15,660 KB |
testcase_26 | AC | 230 ms
15,720 KB |
testcase_27 | AC | 194 ms
15,616 KB |
testcase_28 | AC | 228 ms
15,616 KB |
testcase_29 | AC | 230 ms
15,652 KB |
testcase_30 | AC | 225 ms
15,616 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> ws, iws; 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_ws(int n) { if (ws.size() != (n >> 1)) { ws.resize(n >> 1); Loop(i, n >> 1) ws[i] = exp(cdouble({ 0, 2 * PI * i / n })); } } inline void make_iws(int n) { if (iws.size() != (n >> 1)) { iws.resize(n >> 1); Loop(i, n >> 1) iws[i] = exp(cdouble({ 0, -2 * PI * i / n })); } } // a.size() should be 2^digit void FFT(vector<cdouble>& a) { int n = int(a.size()); int digit = int(rndf(log2(n))); make_ws(n); Loop(i, n) { int j = bit_reverse(i, digit); if (j > i) swap(a[i], a[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 = a[j] + ws[k << mw] * a[j + m]; cdouble y = a[j] - ws[k << mw] * a[j + m]; a[j] = x; a[j + m] = y; ++j; } j += m; } } } // f.size() should be 2^digit void IFFT(vector<cdouble>& f) { int n = int(f.size()); int digit = int(rndf(log2(n))); make_iws(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 = (f[j] + f[j + m]) * 0.5; cdouble r = (f[j] - f[j + m]) * 0.5 * iws[k << mw]; f[j] = q; f[j + m] = r; ++j; } j += m; } } Loop(i, n) { int j = bit_reverse(i, digit); if (j > i) swap(f[i], f[j]); } } 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 - 1); vector<cdouble> a(n, 0), b(n, 0); Loop(i, L) { int abuf; cin >> abuf; abuf--; a[abuf] = 1; } Loop(i, M) { int bbuf; cin >> bbuf; bbuf--; if (bbuf == 0) b[0] = 1; else b[n - bbuf] = 1; } FFT(a); FFT(b); Loop(i, n) a[i] *= b[i]; IFFT(a); int q; cin >> q; Loop(i, q) { cout << rndf(a[i].real()) << endl; } }