結果

問題 No.1307 Rotate and Accumulate
ユーザー fumofumofunifumofumofuni
提出日時 2020-12-04 14:45:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 713 ms / 5,000 ms
コード長 2,835 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 209,408 KB
実行使用メモリ 40,236 KB
最終ジャッジ日時 2023-10-13 03:24:22
合計ジャッジ時間 10,978 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 656 ms
38,960 KB
testcase_09 AC 664 ms
39,136 KB
testcase_10 AC 358 ms
21,532 KB
testcase_11 AC 331 ms
22,196 KB
testcase_12 AC 357 ms
21,684 KB
testcase_13 AC 54 ms
5,832 KB
testcase_14 AC 173 ms
12,476 KB
testcase_15 AC 706 ms
40,048 KB
testcase_16 AC 707 ms
40,112 KB
testcase_17 AC 713 ms
40,068 KB
testcase_18 AC 692 ms
40,000 KB
testcase_19 AC 709 ms
40,180 KB
testcase_20 AC 710 ms
40,236 KB
testcase_21 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


class FFT {//多項式補完のFFT。FFT f;で初期化、auto c=f.multiply(a,b)で受け取り。出力は(ll)round(c[i])。
public:
    static void dft(vector<complex<long double>>& func, int inverse) {
        int sz = func.size();
        if (sz == 1)return;
        vector<complex<long double>> veca, vecb;
        rep(i, sz / 2) {
            veca.push_back(func[2 * i]);
            vecb.push_back(func[2 * i + 1]);
        }
        dft(veca, inverse); dft(vecb, inverse);
        complex<long double> now = 1, zeta = polar(1.0, inverse * 2.0 * acos(-1) / sz);
        rep(i, sz) {
            func[i] = veca[i % (sz / 2)] + now * vecb[i % (sz / 2)];
            now *= zeta;
        }
    }
    template<typename T>
    static vector<long double> multiply(vector<T> f, vector<T> g) {
        while(f.size()!=g.size()){
            if(f.size()<g.size())f.push_back(0);
            else g.push_back(0);
        }
        vector<complex<long double>> nf, ng;
        int sz = 1;
        while (sz < f.size() + g.size())sz *= 2;
        nf.resize(sz); ng.resize(sz);
        rep(i, f.size()) {
            nf[i] = f[i];
            ng[i] = g[i];
        }
        dft(nf, 1);
        dft(ng, 1);
        rep(i, sz)nf[i] *= ng[i];
        dft(nf, -1);
        vector<long double> res;
        rep(i, sz)res.push_back(nf[i].real() / sz);
        return res;
    }
};


int main(){
    ll n,q;cin >> n >> q;
    vl a(n);rep(i,n)cin >> a[i];
    vl x(n);rep(i,q){
        ll a;cin >> a;x[a]++;
    }
    /*rep(i,n){
        ll ret=0;
        rep(j,n){
            ret+=a[(j+i)%n]*x[j];
        }
        cout << ret <<endl;
    }*/
    rev(all(x));
    FFT f;
    vector<ll> ans(n);
    auto c=f.multiply(a,x);
    rep(i,c.size()){
        ans[(i+1)%n]+=round(c[i]);
    }
    rep(i,n)cout << ans[i] <<" ";cout << endl;
}
0