QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575946#3840. Pass the Ball!gankingCompile Error//C++202.6kb2024-09-19 17:34:112024-09-19 17:34:11

Judging History

This is the latest submission verdict.

  • [2024-09-19 17:34:11]
  • Judged
  • [2024-09-19 17:34:11]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long 
#define db long double
#define fo(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define fd(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
using namespace std;
const int N=2e6+10;
const db pi=acos(-1.0);
struct comp{
	db x,y;
	comp(db xx=0,db yy=0) {x=xx;y=yy;}
	friend comp operator + (const comp &a,const comp &b) {return comp(a.x+b.x,a.y+b.y);}
	friend comp operator - (const comp &a,const comp &b) {return comp(a.x-b.x,a.y-b.y);}
	friend comp operator * (const comp &a,const comp &b) {return comp(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);}
}f[N],g[N],a[N],b[N];
int limit=1,len=0,rev[N];
void fft(comp *a,db flag)
{
	for(int i=0;i<limit;i++) 
		if(i<rev[i]) swap(a[i],a[rev[i]]);
		
	for(int mid=1;mid<limit;mid<<=1)
	{
		comp wn(cos(pi/mid),(db)flag*sin(pi/mid));
		for(int l=0,R=(mid<<1);l<limit;l+=R){
			comp w(1,0);
			for(int k=0;k<mid;k++,w=w*wn){
				comp a1=a[l+k],a2=w*a[l+k+mid];
				a[l+k]=a1+a2;
				a[l+k+mid]=a1-a2;
			}
		}
	}
}
vector<ll> ans[N]; //ans[p][k]
int res[N],num,len[N];
void calc(int n,int m,comp* f,comp *g){
	limit=1,len=0,rev[0]=0;
	while(limit<n+m+1) limit<<=1,len++;
	for(int i=1;i<limit;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(len-1));
//	fo(i,0,n){
//		cout<<f[i].x<<" ";
//	}
//	cout<<"\n";
//	fo(i,0,m){
//		cout<<g[i].x<<" ";
//	}
//	cout<<"\n";
	fft(f,1);
	fft(g,1);
	fo(i,0,limit-1){
		f[i]=f[i]*g[i];
	}
	fft(f,-1);
	m++;
	if(res[m]==0){
		res[m]=++num;
		ans[num].resize(m);
		len[num]=m;
	}
	fd(i,2*m-1,m){
		int k=2*m-1-i;
//		cout<<(ll)(f[i].x/limit+0.5)<<"\n";
		ans[res[m]][k]+=(ll)(f[i].x/limit+0.5);
	}
	limit=limit+limit/2;
	fo(i,0,limit) f[i]=g[i]=comp(0,0);
}
int v[N],p[N];
vector<int> e[N];int cnt=0;
void solve(){
	int n,q;
	num=0;
	cin>>n>>q;
	fo(i,1,n) {
		cin>>p[i];
		res[i]=0;
		v[i]=0;
		e[i].clear();
		ans[i].clear();
	}
	fo(i,1,n) {
		if(!v[i]){
			int x=i;
			cnt++;
			while(!v[x]){
				v[x]=1;
				e[cnt].push_back(x);
				x=p[x];
			}
		}
	}
//	fo(i,1,cnt){
//		for(auto y:e[i]) cout<<y<<" ";
//		cout<<"\n";
//	}
	int tot;
	fo(i,1,cnt){
		tot=-1;
		for(auto t:e[i]) {
//			cout<<t<<"?";
			a[++tot]=comp(t,0);
		}
		for(int j=0;j<=tot;j++) {
			b[j]=a[tot-j];
		}
		for(int j=tot+1;j<=2*tot+1;j++) {
			a[j]=a[j-tot-1];
		}
		calc(2*tot+1,tot,a,b);
	}
	int k;ll final;
	fo(i,1,q) {
		cin>>k;
		final=0;
		fo(j,1,num){
			final+=ans[j][k%len[j]];
		}
		cout<<final<<"\n";
	}
}
int main(){
//	freopen("data.in","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	solve();
	return 0;
}
/*

6 4
2 4 1 3 6 5
1
2
3
4

*/

Details

answer.code:36:16: error: conflicting declaration ‘int len [2000010]’
   36 | int res[N],num,len[N];
      |                ^~~
answer.code:16:13: note: previous declaration as ‘int len’
   16 | int limit=1,len=0,rev[N];
      |             ^~~
answer.code: In function ‘void calc(int, int, comp*, comp*)’:
answer.code:59:20: error: invalid types ‘int[int]’ for array subscript
   59 |                 len[num]=m;
      |                    ^
answer.code: In function ‘void solve()’:
answer.code:117:44: error: invalid types ‘int[int]’ for array subscript
  117 |                         final+=ans[j][k%len[j]];
      |                                            ^