QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#259678#7761. 物理实验grass8cow0 713ms23508kbC++174.2kb2023-11-21 10:48:392023-11-21 10:48:40

Judging History

你现在查看的是最新测评结果

  • [2023-11-21 10:48:40]
  • 评测
  • 测评结果:0
  • 用时:713ms
  • 内存:23508kb
  • [2023-11-21 10:48:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
const int mod=998244353,G=3,GI=(mod+1)/3,inv2=(mod+1)/2;
int qpow(int a,int b){
	int c=1;for(;b;b>>=1){
		if(b&1)c=1ll*a*c%mod;
		a=1ll*a*a%mod;
	}
	return c;
}
int L,lb[1<<20];
void init(int n){
	L=1;while(L<=n)L<<=1;
	for(int i=0;i<L;i++)lb[i]=(lb[i>>1]>>1)|((i&1)?(L>>1):0);
}
void NTT(vi &a,int fl){
	for(int i=0;i<L;i++)if(i>lb[i])swap(a[i],a[lb[i]]);
	for(int o=1;o<L;o<<=1){
		int Wn=qpow(fl?G:GI,(mod-1)/(o<<1));
		for(int i=0;i<L;i+=(o<<1))for(int j=0,w=1;j<o;j++,w=1ll*w*Wn%mod){
			int x=a[i+j],y=1ll*w*a[i+j+o]%mod;
			a[i+j]=(x+y)%mod,a[i+j+o]=(x-y)%mod;
		}
	}
	if(!fl){
		int I=qpow(L,mod-2);
		for(int i=0;i<L;i++)a[i]=1ll*a[i]*I%mod;
	}
}
vi operator * (vi a,vi b){
	if(a.empty()||b.empty())return {};
	vi c;int n=a.size()+b.size()-1;init(n);
	a.resize(L),b.resize(L),NTT(a,1),NTT(b,1);
	for(int i=0;i<L;i++)a[i]=1ll*a[i]*b[i]%mod;
	NTT(a,0);
	while((int)a.size()>n)a.pop_back();
	return a;
}
vi operator + (vi a,vi b){
	if(a.empty())return b;if(b.empty())return a;
	if(a.size()<b.size())swap(a,b);int sz=b.size();
	for(int i=0;i<sz;i++)(a[i]+=b[i])%=mod;return a;
}
vi mulT(vi a,vi b){
	//注意:第二个是常量!c_j=sum a_{i-j}b_j a_i=sum c_{i+j}b_{m-1-j}
	int n=a.size(),m=b.size();reverse(b.begin(),b.end());
	b=a*b;
	for(int i=0;i<n;i++)a[i]=b[i+m-1];
	return a;
}
vi az[401000];
void cs(int p,int l,int r,vi &x){
	if(l==r){
		az[p].resize(2);
		az[p][0]=1,az[p][1]=-x[l];
		return;
	}
	int mid=(l+r)>>1;cs(p<<1,l,mid,x),cs(p<<1|1,mid+1,r,x);
	az[p]=az[p<<1]*az[p<<1|1];
}
void cs2(int p,int l,int r,vi &x){
	if(l==r){
		az[p].resize(2);
		az[p][0]=-x[l],az[p][1]=1;
		return;
	}
	int mid=(l+r)>>1;cs2(p<<1,l,mid,x),cs2(p<<1|1,mid+1,r,x);
	az[p]=az[p<<1]*az[p<<1|1];
}
vi WT;
vi Inv(vi &a,int n){
	if(n==1)return vi(1,qpow(a[0],mod-2));
	vi b=Inv(a,(n+1)>>1);
	init(2*n);b.resize(L),WT.resize(L);
	for(int i=0;i<n;i++)WT[i]=a[i];
	for(int i=n;i<L;i++)WT[i]=0;
	NTT(WT,1),NTT(b,1);
	for(int i=0;i<L;i++)b[i]=1ll*b[i]*(2-1ll*b[i]*WT[i]%mod)%mod;
	NTT(b,0);b.resize(n);return b;
}
void Sol(int p,int l,int r,vi x,vi &y){
	x.resize(r-l+1);
	if(l==r){y[l]=x[0];return;}
	int mid=(l+r)>>1;
	Sol(p<<1,l,mid,mulT(x,az[p<<1|1]),y);
	Sol(p<<1|1,mid+1,r,mulT(x,az[p<<1]),y);
}
vi Qz(vi a,vi b,int n){
	a.resize(n+1),b.resize(n);
	vi c;cs(1,0,n-1,b);
	c.resize(n);
	Sol(1,0,n-1,mulT(a,Inv(az[1],n+1)),c);
	return c;
}
struct mat{vi a[2][2];};
mat operator * (const mat &a,const mat &b){
	mat c;for(int k=0;k<2;k++)for(int i=0;i<2;i++)for(int j=0;j<2;j++){
		vi xp=a.a[i][k]*b.a[k][j];
		c.a[i][j]=c.a[i][j]+xp;
	}
	return c;
}
int sol(vi p,vi q,int n){
    if(!n)return 1ll*p[0]*qpow(q[0],mod-2)%mod;
    vi q_;
    for(int i=0;i<(int)q.size();i++)q_.pb((i&1)?(-q[i]):q[i]);
    vi P=p*q_,Q=q*q_,A,B,q2;
    for(int i=0;i*2<(int)Q.size();i++)q2.pb(Q[i*2]);
    for(int i=0;i*2<(int)P.size();i++)A.pb(P[i*2]);
    for(int i=0;i*2+1<(int)P.size();i++)B.pb(P[i*2+1]);
    if(n&1)return sol(B,q2,n>>1);
    return sol(A,q2,n>>1);
}
int n,m,P,lp,rp,a[101000],b[100100],f[101000];
int od[5010],od2[5010];
int main(){
	scanf("%d%d%d%d%d",&n,&m,&P,&lp,&rp);
	P=1ll*P*(1-P)%mod;
	vi a1,a2;
	for(int i=0;i<m;i++)a1.pb(0),a2.pb(0);
	for(int i=0,x;i<n;i++)scanf("%d",&x),a1[x]++,a2[(m-x)%m]++;
	a1=a1*a2;
	for(int i=0;i<(int)a1.size();i++){int e=i%m;e=min(e,m-e);(a[e]+=a1[i])%=mod;}
	for(int i=1;i<m;i++)a[i]=1ll*a[i]*inv2%mod,b[i]=min(i,m-i);m--;
	mat A,B;A.a[0][0]={(2*P-1)%mod,1},A.a[0][1]={1};
	B.a[0][0]={(2*P-1)%mod,1},B.a[0][1]={1},B.a[1][0]={-(int)(1ll*P*P%mod)};
	for(int o=m;o;o>>=1){if(o&1)A=A*B;B=B*B;}
	vi q=A.a[0][1];
	reverse(q.begin(),q.end());
	for(int i=1;i<=m;i++)od[i]=a[i];
	for(int i=0;i<m;i++){
		memset(od2,0,sizeof(od2));
		for(int j=1;j<=m;j++)(f[i]+=1ll*od[j]*b[j]%mod)%=mod;
		for(int j=1;j<=m;j++){
			(od2[j+1]+=1ll*od[j]*P%mod)%=mod;
			(od2[j-1]+=1ll*od[j]*P%mod)%=mod;
			(od2[j]+=1ll*od[j]*(1-P*2)%mod)%=mod; 
		}
		for(int j=1;j<=m;j++)od[j]=od2[j];
	}
	vi p;
	for(int i=0;i<m;i++){
		int ks=0;
		for(int j=0;j<=i;j++)(ks+=1ll*f[i-j]*q[j]%mod)%=mod;
		p.push_back(ks);
	}
	for(int i=lp;i<=rp;i++)printf("%d ",(sol(p,q,i)+mod)%mod);
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

7500 7500 96132844 1 7500
1791 817 5559 4742 5272 3988 6672 1355 2783 5552 6885 5321 5996 6495 3072 2241 5527 856 6250 2741 4223 1560 6529 5330 3517 2637 6577 244 1739 5147 2648 6466 1479 7340 7355 176 183 1417 2943 5134 3879 3574 734 4880 7451 3778 1466 5237 2015 1334 6105 4859 1331 5805 3175 4795 ...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 713ms
memory: 23508kb

input:

100000 7500 500440646 935892941 935892941
3280 7218 1216 489 4036 7029 5538 4805 2544 568 4303 816 739 2284 1294 6062 808 3029 3565 4344 7124 3917 705 3637 6076 2019 4233 2032 7327 5672 2872 2593 22 1534 2071 5782 3228 5460 1217 5138 7285 3679 2751 213 2242 2673 2746 7041 7001 860 2591 7347 3330 213...

output:

256225811 

result:

wrong answer 1st numbers differ - expected: '768801558', found: '256225811'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Time Limit Exceeded

Test #9:

score: 0
Time Limit Exceeded

input:

100000 50000 559705157 50000 50000
27437 48841 4744 41269 30017 24703 22660 38617 9707 42083 31500 14053 45335 20769 16455 30887 31847 6833 44822 14557 15400 18868 15093 47184 35490 48961 45686 45613 297 31598 7021 9194 30432 14570 44495 39114 21800 16034 12668 49738 20083 31717 22713 34958 46363 35...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #7:

0%

Subtask #9:

score: 0
Skipped

Dependency #6:

0%

Subtask #10:

score: 0
Skipped

Dependency #4:

0%