結果
| 問題 |
No.1307 Rotate and Accumulate
|
| コンテスト | |
| ユーザー |
kyoprouno
|
| 提出日時 | 2020-12-04 21:26:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 3,016 bytes |
| コンパイル時間 | 3,486 ms |
| コンパイル使用メモリ | 204,204 KB |
| 実行使用メモリ | 817,320 KB |
| 最終ジャッジ日時 | 2024-09-15 08:07:29 |
| 合計ジャッジ時間 | 6,422 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 MLE * 1 -- * 13 |
ソースコード
#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;
}
kyoprouno