結果

問題 No.1307 Rotate and Accumulate
ユーザー kyoprounokyoprouno
提出日時 2020-12-04 21:26:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 3,016 bytes
コンパイル時間 3,394 ms
コンパイル使用メモリ 202,084 KB
実行使用メモリ 813,684 KB
最終ジャッジ日時 2023-10-13 11:06:04
合計ジャッジ時間 8,472 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,352 KB
testcase_01 AC 11 ms
4,352 KB
testcase_02 AC 23 ms
4,348 KB
testcase_03 AC 209 ms
4,640 KB
testcase_04 AC 215 ms
5,108 KB
testcase_05 AC 215 ms
4,792 KB
testcase_06 AC 215 ms
4,588 KB
testcase_07 AC 212 ms
4,348 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}



template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e9+7;

int n;
int m=1;

vector<complex<double>> f,g;

struct FastFourierTransform{
    static void dft(vector<complex<double>>& func, int inverse){
        int sz=func.size();
        if(sz==1) return ;
        vector<complex<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<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<double> multiply(vector<T> f,vector<T> g){
        vector<complex<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<double> res;
        rep(i,sz)res.push_back(nf[i].real()/sz);
        return res;
    }
};


int main(){
    ios;
    ll n,q;
    cin >> n >> q;
    vector<ll> a(n);
    vector<ll> r(q);
    vector<ll> ans(n);
    vector<vector<ll>> cnt(1001,vector<ll>(n)),sum(1001,vector<ll>(n));
    rep(i,n){
        cin >> a[i];
        cnt[a[i]][i]=1;
    }
    rep(i,q){
        cin >> r[i];
    }
    while(m<2*n || m<2*q) m*=2;
    f.resize(m);
    g.resize(m);
    for(ll i=0;i<=1000;i++){
        FastFourierTransform FFT;
        rep(j,n){
            f[j]=cnt[i][j];
        }
        rep(j,q){
            g[(n-r[j])%n]+=1;
        }
        FFT.dft(f,1);
        FFT.dft(g,1);
        rep(j,m){
            f[j]*=g[j];
        }
        FFT.dft(f,-1);
        rep(j,2*n){
            sum[i][j%n]+=(ll)(f[j].real()/m+0.1);
        }
        rep(j,m){
            f[j]=0;
            g[j]=0;
        }
    }
    for(ll i=0;i<=1000;i++){
        rep(j,n){
            ans[j]+=sum[i][j]*i;
        }
    }
    rep(i,n){
        if(i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}
0