結果

問題 No.1307 Rotate and Accumulate
ユーザー nrvftnrvft
提出日時 2020-12-06 03:45:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 177 ms / 5,000 ms
コード長 3,204 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 215,292 KB
実行使用メモリ 40,864 KB
最終ジャッジ日時 2023-10-17 00:40:29
合計ジャッジ時間 6,778 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 156 ms
38,728 KB
testcase_09 AC 174 ms
38,968 KB
testcase_10 AC 90 ms
22,512 KB
testcase_11 AC 83 ms
22,000 KB
testcase_12 AC 103 ms
22,464 KB
testcase_13 AC 17 ms
6,240 KB
testcase_14 AC 46 ms
12,948 KB
testcase_15 AC 171 ms
40,864 KB
testcase_16 AC 172 ms
40,864 KB
testcase_17 AC 170 ms
40,864 KB
testcase_18 AC 170 ms
40,864 KB
testcase_19 AC 177 ms
40,864 KB
testcase_20 AC 173 ms
40,864 KB
testcase_21 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0