QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#55902#3840. Pass the Ball!Ctrl2333#Compile Error//C++173.1kb2022-10-15 16:04:452022-10-15 16:04:48

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 16:04:48]
  • Judged
  • [2022-10-15 16:04:45]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar

const long double pi=acos(-1.0);

namespace IO{
    inline int getint(){
        char c;
        while(!isdigit(c=gc()));int num=c^48;
        while(isdigit(c=gc()))num=(num+(num<<2)<<1)+(c^48);
        return num;
    }
}
using namespace IO;


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(2*pi.0/h),sin(typ*2.0*pi/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){
    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(){
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
        scanf("%d",&f[i]);
    }
    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++){
            ans+=(long long)(poly[ring[i]][k%ring[i]+ring[i]-1].x);
        }
        printf("%lld\n",ans);
    }
}

详细

answer.code: In function ‘void FFT(Poly&, int, int)’:
answer.code:44:25: error: expected ‘)’ before numeric constant
   44 |         Comp wn(cos(2*pi.0/h),sin(typ*2.0*pi/h));
      |                    ~    ^~
      |                         )
answer.code: In function ‘void print(Poly&)’:
answer.code:87:19: warning: format ‘%lf’ expects argument of type ‘double’, but argument 2 has type ‘long double’ [-Wformat=]
   87 |         printf("%lf ",a[i].x);
      |                 ~~^
      |                   |
      |                   double
      |                 %Lf
answer.code: In function ‘int main()’:
answer.code:117:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  117 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
answer.code:119:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  119 |         scanf("%d",&f[i]);
      |         ~~~~~^~~~~~~~~~~~
answer.code:129:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  129 |         long long k;scanf("%lld",&k);
      |                     ~~~~~^~~~~~~~~~~