QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187056 | #3840. Pass the Ball! | bzw | WA | 8ms | 34452kb | C++14 | 2.2kb | 2023-09-24 14:09:58 | 2023-09-24 14:09:58 |
Judging History
answer
// qwq
#include <bits/stdc++.h>
using namespace std;
constexpr int N=1e6+1;
struct cp{
long double a,b;
cp operator + (cp o){return {a+o.a,b+o.b};}
cp operator - (cp o){return {a-o.a,b-o.b};}
cp operator * (cp o){return {a*o.a-b*o.b,a*o.b+b*o.a};}
};
const long double pi=acos(-1);
cp w[N]; int rev[N];
void fft(cp* a,int len,bool ok){
for(int i=0;i<len;i++){
rev[i]=(rev[i>>1]>>1)+(i&1?len>>1:0);
if(rev[i]>i)swap(a[rev[i]],a[i]);
}
for(int d=1;d<len;d<<=1){
cp W={cos(pi/d),sin(pi/d)};if(ok)W.b=-W.b;
w[0]={1.,0.}; for(int i=1;i<d;i++)w[i]=w[i-1]*W;
for(int fi=0;fi<len;fi+=d<<1){
int se=fi+d;
for(int i=0;i<d;i++){
cp a0=a[fi+i],a1=a[se+i]*w[i];
a[fi+i]=(a0+a1),a[se+i]=(a0-a1);
}
}
}
if(ok){
for(int i=0;i<len;i++)
a[i].a/=len;
}
}
typedef long long ll;
typedef vector<ll> arr;
cp f[N],g[N];
arr mul(arr x,arr y){
int n=x.size(),m=y.size(),len=1;
while(len<=(n*3+3))len<<=1;
for(int i=0;i<len;i++)f[i]=g[i]={0.,0.};
for(int i=0;i<n;i++)f[i+n].a=f[i].a=x[i];
for(int i=0;i<n;i++)g[i].a=y[n-1-i];
fft(f,len,0),fft(g,len,0);
for(int i=0;i<len;i++)f[i]=f[i]*g[i];
fft(f,len,1);
arr cur(n,0);
for(int i=0;i<n;i++)
cur[i]=ll(f[n-1+i].a+0.5);
return cur;
}
arr Mul(arr x,arr y){
arr a=x,b=y,c=x,d=y;
int n=x.size();
for(int i=0;i<n;i++)
a[i]/=1000,b[i]/=1000,
c[i]%=1000,d[i]%=1000;
a=mul(a,b),c=mul(c,d);
for(int i=0;i<n;i++)
a[i]=a[i]*1000000ll+c[i];
return a;
}
arr e[N],s; int n,m,vis[N],p[N];
int main(){
cin>>n>>m;for(int i=1;i<=n;i++)cin>>p[i];
for(int i=1;i<=n;i++)if(!vis[i]){
int x=i,t=0;arr a;
while(!vis[x])a.push_back(x),vis[x]=1,x=p[x],t++;
a=Mul(a,a);
if(e[t].size()==0){
s.push_back(t);
e[t]=a;
}
else{
for(int j=0;j<t;j++)
e[t][j]+=a[j];
}
}
while(m--){
int q;cin>>q;
ll ans=0;
for(ll i:s)
ans+=e[i][q%i];
cout<<ans<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 32224kb
input:
4 4 2 4 1 3 1 2 3 4
output:
25 20 25 30
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 4ms
memory: 34272kb
input:
3 6 2 3 1 1 2 3 999999998 999999999 1000000000
output:
11 11 14 11 14 11
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 3ms
memory: 32328kb
input:
3 6 3 1 2 1 2 3 999999998 999999999 1000000000
output:
11 11 14 11 14 11
result:
ok 6 lines
Test #4:
score: -100
Wrong Answer
time: 8ms
memory: 34452kb
input:
1000 10000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
332334000 331835500 331338000 330841500 330346000 329851500 329358000 328865500 328374000 327883500 327394000 326905500 326418000 325931500 325446000 324961500 324478000 323995500 323514000 323033500 322554000 322075500 321598000 321121500 320646000 320171500 319698000 319225500 318754000 318283500 ...
result:
wrong answer 1st lines differ - expected: '333334000', found: '332334000'