QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#55923#3840. Pass the Ball!Ctrl2333#WA 2ms6524kbC++203.2kb2022-10-15 17:15:262022-10-15 17:15:38

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-15 17:15:38]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 6524kb
  • [2022-10-15 17:15:26]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
const long double pi=acos((long double)-1.0);

struct Comp{
    long double x,y;
    Comp(long double _x=0.0,long double _y=0.0){
        x=_x,y=_y;
    }
    Comp operator -(const Comp &b)const{
        return Comp(x-b.x,y-b.y);
    }
    Comp operator +(const Comp &b)const{
        return Comp(x+b.x,y+b.y);
    }
    Comp operator *(const Comp &b)const{
        return Comp(x*b.x-y*b.y,x*b.y+y*b.x);
    }
};

const int maxn=3010000;

typedef vector<Comp> Poly;

int r[maxn];
inline void FFT(Poly &A,int len, int typ){
    for(int i=0;i<len;i++)if(i<r[i])swap(A[i],A[r[i]]);
    for(int h=2;h<=len;h<<=1){
        Comp wn(cos((long double)2.0*pi/(long double)h),sin((long double)typ*(long double)2.0*pi/(long double)h));
        for(int j=0;j<len;j+=h){
            Comp w(1,0);
            for(int k=j;k<j+(h>>1);k++){
                Comp u=A[k], t=w*A[k+(h>>1)];
                A[k]=u+t,A[k+(h>>1)]=u-t;
                w=w*wn;
            }
        }
    }
    if(typ==-1)for(int i=0;i<len;i++)A[i].x/=(long double)len;
}
inline void init_rev(int len){
    for(int i=0;i<len;i++)r[i]=r[i>>1]>>1|((i&1)*(len>>1));
}

inline Poly operator+(const Poly &a, const Poly &b){
    Poly c=a;c.resize(max(a.size(),b.size()));
    for(int i=0;i<b.size();i++)c[i]=c[i]+b[i];
    return c;
}

Poly operator*(Poly a,Poly b){
    int n=a.size(),m=b.size(),l=1;
    while(l<n+m-1)l<<=1;
    init_rev(l);
    a.resize(l),FFT(a,l,1);
    b.resize(l),FFT(b,l,1);
    for(int i=0;i<l;i++)a[i]=a[i]*b[i];
    FFT(a,l,-1);
    a.resize(n+m-1);
    return a;
}


int n,q;
int f[100005];
Poly poly[100005];
vector<int>ring;
int vis[100005];
int stk[100005],top;
inline void print(Poly &a){
    for(int i=0;i<a.size();i++){
        printf("%lf ",a[i].x);
    }
    printf("\n");
}
void dfs(int u){
    //cout<<"U:"<<u<<endl;
    vis[u]=1;
    stk[++top]=u;
    if(vis[f[u]]){
        Poly p1,p2;
        for(int k=0;k<2;k++){
            for(int i=1;i<=top;i++){
                Comp ne(stk[i],0);
                p1.push_back(ne);
            }
        }
        for(int i=top;i>=1;i--){
            //cout<<"U:"<<u<<" node:"<<stk[i]<<endl;
            Comp ne(stk[i],0);
            p2.push_back(ne);
        }
        Poly res=p1*p2;
        //print(res);
        poly[top] = poly[top] + res;
    }
    else{
        dfs(f[u]);
    }
    top--;
}
int main(){
    //long long xx=0;
    //for(long long i=1;i<=100000ll;i++)xx+=i*i;
    //cout<<"X:"<<xx<<endl;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
        scanf("%d",&f[i]);
        //f[i]=i%n+1;
    }
    for(int i=1;i<=n;i++){
        if(!vis[i])dfs(i);
    }
    for(int i=2;i<=100000;i++){
        if(poly[i].size())ring.push_back(i);
        //print(poly[i]);
    }
    for(int qq=1;qq<=q;qq++){
        long long k;scanf("%lld",&k);
        long long ans=0;
        for(int i=0;i<ring.size();i++){
            //printf("%.20Lf\n",poly[ring[i]][k%ring[i]+ring[i]-1].x);
            ans+=ceil(poly[ring[i]][k%ring[i]+ring[i]-1].x);
        }
        printf("%lld\n",ans);
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6180kb

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

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

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

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:

333334000
332835500
332338000
331841500
331346000
330851500
330358000
329865500
329374000
328883500
328394000
327905500
327418000
326931500
326446000
325961500
325478000
324995500
324514000
324033500
323554000
323075500
322598000
322121500
321646001
321171501
320698001
320225501
319754001
319283501
...

result:

wrong answer 25th lines differ - expected: '321646000', found: '321646001'