QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#234402 | #3840. Pass the Ball! | GFFF | Compile Error | / | / | C++14 | 2.2kb | 2023-11-01 16:55:35 | 2023-11-01 16:55:35 |
Judging History
This is the latest submission verdict.
- [2023-11-01 16:55:35]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2023-11-01 16:55:35]
- Submitted
answer
#include<bits/stdc++.h>
using namespace std;
typedef __float128 ld;
typedef long long ll;
const int maxn=1e6+5;
const ld pi=acosl(-1.0);
struct cpl{
ld x,y;
cpl friend operator + (const cpl a,const cpl b) {return (cpl){a.x+b.x,a.y+b.y};}
cpl friend operator - (const cpl a,const cpl b) {return (cpl){a.x-b.x,a.y-b.y};}
cpl friend operator * (const cpl a,const cpl b) {return (cpl){a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x};}
}A[maxn],B[maxn],C[maxn];
struct FNTT{
int mx,tim,r[maxn];
void FFT(cpl *a,int op)
{
for(int i=0;i<mx;++i) if(i<r[i]) swap(a[i],a[r[i]]);
for(int mid=1;mid<mx;mid<<=1)
{
cpl wn=(cpl){cosl(pi/mid),op*sinl(pi/mid)};
for(int i=0,len=mid<<1;i<mx;i+=len)
{
cpl w=(cpl){1,0};
for(int j=0;j<mid;++j,w=w*wn)
{
cpl x=a[i+j],y=w*a[i+mid+j];
a[i+j]=x+y;a[i+mid+j]=x-y;
}
}
}
if(op==1) return ;
for(int i=0;i<mx;++i) a[i].x/=mx;
}
int getlen(int n) {for(mx=1,tim=0;mx<=n;mx<<=1,++tim);return mx;}
void Mul(int n,int *a,int *b,ll *c)
{
for(int i=0;i<mx;++i) r[i]=(r[i>>1]>>1)|((i&1)<<(tim-1));
for(int i=0;i<mx;++i) A[i]=(cpl){a[i],0},B[i]=(cpl){b[i],0};
FFT(A,1);FFT(B,1);
for(int i=0;i<mx;++i) C[i]=A[i]*B[i];
FFT(C,-1);
for(int i=0;i<n;++i) c[i]=(ll)round(C[i].x);
}
}fntt;
int n,cnt,q,p[maxn],yet[maxn],a[maxn],b[maxn];
ll ans,c[maxn];
vector<ll> d[maxn];
vector<int> bl[maxn];
vector<int> lenth;
void dfs(int x,int id)
{
yet[x]=1;
bl[id].push_back(x);
if(!yet[p[x]]) dfs(p[x],id);
}
void work(int id)
{
int N=bl[id].size();
int mx=fntt.getlen(N*3);
for(int i=0;i<mx;++i) a[i]=b[i]=c[i]=0;
for(int i=0;i<N;++i) a[i]=b[i]=bl[id][i];
reverse(b,b+N);
for(int i=N;i<N*2;++i) b[i]=b[i-N];
fntt.Mul(N*3,a,b,c);
if(!d[N].size()) d[N].resize(N),lenth.push_back(N);
for(int i=0;i<N;++i) d[N][i]+=c[i+N-1];
}
int main()
{
scanf("%d%d",&n,&q);
for(int i=1;i<=n;++i) scanf("%d",&p[i]);
for(int i=1;i<=n;++i)
if(!yet[i])
{
++cnt;
dfs(i,cnt);
}
for(int i=1;i<=cnt;++i) work(i);
for(int i=1,x;i<=q;++i)
{
scanf("%d",&x);
ans=0;
for(auto len:lenth) ans+=d[len][x%len];
printf("%lld\n",ans);
}
return 0;
}
/*
5 100
2 3 1 5 4
*/
詳細信息
answer.code: In member function ‘void FNTT::Mul(int, int*, int*, ll*)’: answer.code:38:53: warning: narrowing conversion of ‘*(a + ((sizetype)(((long unsigned int)i) * 4)))’ from ‘int’ to ‘ld’ {aka ‘__float128’} [-Wnarrowing] 38 | for(int i=0;i<mx;++i) A[i]=(cpl){a[i],0},B[i]=(cpl){b[i],0}; | ~~~^ answer.code:38:72: warning: narrowing conversion of ‘*(b + ((sizetype)(((long unsigned int)i) * 4)))’ from ‘int’ to ‘ld’ {aka ‘__float128’} [-Wnarrowing] 38 | for(int i=0;i<mx;++i) A[i]=(cpl){a[i],0},B[i]=(cpl){b[i],0}; | ~~~^ answer.code:42:52: error: call of overloaded ‘round(ld&)’ is ambiguous 42 | for(int i=0;i<n;++i) c[i]=(ll)round(C[i].x); | ~~~~~^~~~~~~~ In file included from /usr/include/features.h:461, from /usr/include/x86_64-linux-gnu/c++/11/bits/os_defines.h:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:586, from /usr/include/c++/11/cassert:43, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:33, from answer.code:1: /usr/include/x86_64-linux-gnu/bits/mathcalls.h:298:1: note: candidate: ‘double round(double)’ 298 | __MATHCALLX (round,, (_Mdouble_ __x), (__const__)); | ^~~~~~~~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41, from answer.code:1: /usr/include/c++/11/cmath:1760:3: note: candidate: ‘constexpr long double std::round(long double)’ 1760 | round(long double __x) | ^~~~~ /usr/include/c++/11/cmath:1756:3: note: candidate: ‘constexpr float std::round(float)’ 1756 | round(float __x) | ^~~~~ answer.code: In function ‘int main()’: answer.code:70:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 70 | scanf("%d%d",&n,&q); | ~~~~~^~~~~~~~~~~~~~ answer.code:71:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 71 | for(int i=1;i<=n;++i) scanf("%d",&p[i]); | ~~~~~^~~~~~~~~~~~ answer.code:81:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 81 | scanf("%d",&x); | ~~~~~^~~~~~~~~