結果
問題 | No.1307 Rotate and Accumulate |
ユーザー | nrvft |
提出日時 | 2020-12-06 03:45:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 198 ms / 5,000 ms |
コード長 | 3,204 bytes |
コンパイル時間 | 2,523 ms |
コンパイル使用メモリ | 213,252 KB |
実行使用メモリ | 40,964 KB |
最終ジャッジ日時 | 2024-09-17 00:12:36 |
合計ジャッジ時間 | 6,577 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 178 ms
38,860 KB |
testcase_09 | AC | 183 ms
38,984 KB |
testcase_10 | AC | 101 ms
22,656 KB |
testcase_11 | AC | 93 ms
22,012 KB |
testcase_12 | AC | 102 ms
22,464 KB |
testcase_13 | AC | 19 ms
6,944 KB |
testcase_14 | AC | 53 ms
12,976 KB |
testcase_15 | AC | 197 ms
40,904 KB |
testcase_16 | AC | 194 ms
40,700 KB |
testcase_17 | AC | 194 ms
40,928 KB |
testcase_18 | AC | 188 ms
40,964 KB |
testcase_19 | AC | 196 ms
40,876 KB |
testcase_20 | AC | 198 ms
40,836 KB |
testcase_21 | AC | 2 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; template<class T> using vc = vector<T>; template<class T> using vvc = vector<vector<T>>; #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (ll i = (l); i < (r); i++) #define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--) #define repa(i,n) for (auto& i: n) template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;} template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;} struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_; #ifdef DEBUG template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; } ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; } template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); } #endif const ll INF = 4e18; const ld EPS = 1e-11; const ld PI = acos(-1.0L); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; //--------------------------------------------------------------------------------// template<class T> struct FFT { FFT(): pi(acos(-1.0L)), sz(1){} private: const long double pi; int sz; vector<complex<long double>> tmp; vector<complex<long double>> fft(vector<complex<long double>> a, bool isinv = false){ int mask = sz - 1, p = 0; for (int i = sz >> 1; i >= 1; i >>= 1) { auto& cur = (p & 1) ? tmp : a; auto& nxt = (p & 1) ? a : tmp; complex<long double> e = polar(1.0L, 2 * pi * i * (isinv ? -1 : 1) / sz), w = 1; for (int j = 0; j < sz; j += i) { for (int k = 0; k < i; ++k) { nxt[j + k] = cur[(j << 1 & mask) + k] + w * cur[(((j << 1) + i) & mask) + k]; } w *= e; } ++p; } if (p & 1) swap(a, tmp); if (isinv) for (int i = 0; i < sz; ++i) a[i] /= sz; return a; } public: vector<T> multiply(vector<T> a, vector<T> b) { int an = a.size(), bn = b.size(), m = an + bn - 1; sz = 1; while (m > sz) sz <<= 1; tmp.resize(sz); vector<complex<long double>> fa(sz), fb(sz); for (int i = 0; i < an; ++i) fa[i].real(a[i]); for (int i = 0; i < bn; ++i) fb[i].real(b[i]); fa = fft(fa), fb = fft(fb); for (int i = 0; i < sz; ++i) fa[i] *= fb[i]; fa = fft(fa, true); a.resize(m); for (int i = 0; i < m; ++i) a[i] = round(fa[i].real()); return a; } }; int main() { ll N, Q; cin >> N >> Q; vl A(N), R(Q); rep(i, N) cin >> A[i]; rep(i, Q) cin >> R[i]; vl C(N); rep(i, Q) C[(R[i] == 0 ? 0 : N - R[i])]++; FFT<ll> fft; vl T = fft.multiply(C, A); repe(i, N, 2 * N - 1) T[i - N] += T[i]; rep(i, N) cout << T[i] << " "; cout << endl; }