QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#187061#3840. Pass the Ball!bzwWA 7ms28740kbC++142.3kb2023-09-24 14:12:532023-09-24 14:12:54

Judging History

This is the latest submission verdict.

  • [2023-09-24 14:12:54]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 28740kb
  • [2023-09-24 14:12:53]
  • Submitted

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]/=100,b[i]/=100,
        c[i]%=100,d[i]%=100;
    arr E[4]={mul(a,b),mul(a,c),mul(b,d),mul(c,d)};
    for(int i=0;i<n;i++)
        a[i]=E[0][i]*10000ll+(E[1][i]+E[2][i])*100ll+E[3][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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 6ms
memory: 28240kb

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: 0ms
memory: 28532kb

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: 0ms
memory: 27600kb

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: 7ms
memory: 28740kb

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:

333432000
332931500
332432000
331933500
331436000
330939500
330444000
329949500
329456000
328963500
328472000
327981500
327492000
327003500
326516000
326029500
325544000
325059500
324576000
324093500
323612000
323131500
322652000
322173500
321696000
321219500
320744000
320269500
319796000
319323500
...

result:

wrong answer 1st lines differ - expected: '333334000', found: '333432000'