QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#262092#7761. 物理实验zhouhuanyi10 473ms129180kbC++146.5kb2023-11-23 15:29:392023-11-23 15:29:39

Judging History

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

  • [2023-11-23 15:29:39]
  • 评测
  • 测评结果:10
  • 用时:473ms
  • 内存:129180kb
  • [2023-11-23 15:29:39]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#define N 200000
#define K 524288
#define M 20
#define g 3
#define mod 998244353
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
void Adder2(int &x,int d)
{
	x+=d;
	if (x<0) x+=mod;
	return;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
int fast_pow(int a,int b)
{
	int res=1,mul=a;
	while (b)
	{
		if (b&1) res=1ll*res*mul%mod;
		mul=1ll*mul*mul%mod,b>>=1;
	}
	return res;
}
int n,m,length,p,L,R,tong[N+1],leng,tong2[N+1],leng2,res[N+1],cnt[N+1],dp[N+1],rev[K+1],wn[M+1][K+1],wn2[M+1][K+1],A[K+1],B[K+1],num[K+1];
void NTT(int limit,int *s,int type)
{
	int s1,s2;
	for (int i=1;i<limit;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(limit>>1):0);
	for (int i=0;i<limit;++i)
		if (rev[i]>i)
			swap(s[i],s[rev[i]]);
	if (type==1)
	{
		for (int i=2;i<=limit;i<<=1)
			for (int j=0;j+i-1<limit;j+=i)
				for (int k=j;k<j+(i>>1);++k)
					s1=s[k],s2=1ll*s[k+(i>>1)]*wn[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
	}
	else
	{
		for (int i=2;i<=limit;i<<=1)
			for (int j=0;j+i-1<limit;j+=i)
				for (int k=j;k<j+(i>>1);++k)
					s1=s[k],s2=1ll*s[k+(i>>1)]*wn2[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
		for (int i=0;i<limit;++i) s[i]=1ll*s[i]*fast_pow(limit,mod-2)%mod;
	}
	return;
}
struct reads
{
	int d[N+1];
};
reads e,nw,nws,c,cs,zero;
reads operator * (reads a,reads b)
{
	c=zero;
	int limit=1;
	while (limit<=(m<<2)) limit<<=1;
	for (int i=0;i<=limit;++i) A[i]=B[i]=0;
	for (int i=0;i<(m<<1);++i) A[i]=a.d[i],B[i]=b.d[i];
	NTT(limit,A,1),NTT(limit,B,1);
	for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
	NTT(limit,A,-1);
	for (int i=0;i<(m<<2);++i) Adder(c.d[i%(m<<1)],A[i]);
	return c;
}
reads fast_pow(reads a,int b)
{
	int limit=1;
	while (limit<=(m<<2)) limit<<=1;
	reads res=e,mul=a;
	while (b)
	{
		if (b&1)
		{
			leng=leng2=0;
			for (int i=0;i<(m<<1);++i)
			{
				if (mul.d[i]) tong[++leng]=i;
				if (res.d[i]) tong2[++leng2]=i;
			}
			if (leng<=5000&&leng2<=5000)
			{
				c=cs=zero;
				for (int i=1;i<=leng;++i)
				{
					for (int j=1;j<=leng;++j) Adder(c.d[(tong[i]+tong[j])%(m<<1)],1ll*mul.d[tong[i]]*mul.d[tong[j]]%mod);
					for (int j=1;j<=leng2;++j) Adder(cs.d[(tong[i]+tong2[j])%(m<<1)],1ll*mul.d[tong[i]]*res.d[tong2[j]]%mod);
				}
				mul=c,res=cs;
			}
			else
			{
				for (int i=0;i<=limit;++i) A[i]=B[i]=0;
				for (int i=0;i<(m<<1);++i) A[i]=mul.d[i],B[i]=res.d[i];
				NTT(limit,A,1),NTT(limit,B,1);
				for (int i=0;i<=limit;++i) B[i]=1ll*A[i]*B[i]%mod,A[i]=1ll*A[i]*A[i]%mod;
				NTT(limit,A,-1),NTT(limit,B,-1);
				for (int i=0;i<(m<<1);++i) mul.d[i]=A[i],res.d[i]=B[i];
			}
		}
		else
		{
			leng=0;
			for (int i=0;i<(m<<1);++i)
				if (mul.d[i])
					tong[++leng]=i;
			if (leng<=5000)
			{
				c=zero;
				for (int i=1;i<=leng;++i)
					for (int j=1;j<=leng;++j)
						Adder(c.d[(tong[i]+tong[j])%(m<<1)],1ll*mul.d[tong[i]]*mul.d[tong[j]]%mod);
				mul=c;
			}
			else
			{
				for (int i=0;i<=limit;++i) A[i]=0;
				for (int i=0;i<(m<<1);++i) A[i]=mul.d[i];
				NTT(limit,A,1);
				for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*A[i]%mod;
				NTT(limit,A,-1);
				for (int i=0;i<(m<<1);++i) mul.d[i]=A[i];
			}
		}
		b>>=1;
	}
	return res;
}
vector<int>operator * (vector<int>a,vector<int>b)
{
	int limit=1;
	vector<int>c(a.size()+b.size()-1);
	while (limit<=a.size()+b.size()) limit<<=1;
	for (int i=0;i<=limit;++i) A[i]=B[i]=0;
	for (int i=0;i<a.size();++i) A[i]=a[i];
	for (int i=0;i<b.size();++i) B[i]=b[i];
	NTT(limit,A,1),NTT(limit,B,1);
	for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
	NTT(limit,A,-1);
	for (int i=0;i<c.size();++i) c[i]=A[i];
	return c;
}
struct seg
{
	struct node
	{
		int l,r;
		vector<int>data;
	};
	node tree[(N<<2)+1];
	void push_up(int k)
	{
		tree[k].data=tree[k<<1].data*tree[k<<1|1].data;
		return;
	}
	void build(int k,int l,int r)
	{
		tree[k].l=l,tree[k].r=r;
		if (l==r)
		{
			tree[k].data={1ll*p*MD2(1-p)%mod,MD(1ll*p*p%mod+1ll*MD2(1-p)*MD2(1-p)%mod),1ll*p*MD2(1-p)%mod};
			return;
		}
		int mid=(l+r)>>1;
		build(k<<1,l,mid),build(k<<1|1,mid+1,r),push_up(k);
		return;	
	}
	void solve(int k,vector<int>sp)
	{
		if (tree[k].l==tree[k].r)
		{
			res[tree[k].l]=sp[1];
			return;
		}
		int limit=1;
		vector<int>sp1(tree[k<<1].data.size());
		vector<int>sp2(tree[k<<1|1].data.size());
		for (int i=0;i<tree[k<<1].data.size();++i) sp1[i]=sp[i+(tree[k<<1|1].data.size()>>1)];
		while (limit<=tree[k].data.size()) limit<<=1;
		for (int i=0;i<=limit;++i) A[i]=B[i]=0;
		for (int i=0;i<tree[k].data.size();++i) A[i]=sp[i];
		for (int i=0;i<tree[k<<1].data.size();++i) B[tree[k<<1].data.size()-i]=tree[k<<1].data[i];
		NTT(limit,A,1),NTT(limit,B,1);
		for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
		NTT(limit,A,-1);
		for (int i=0;i<tree[k<<1|1].data.size();++i) sp2[i]=A[tree[k<<1].data.size()+i];
		solve(k<<1,sp1),solve(k<<1|1,sp2);
		return;
	}
};
seg T;
int main()
{
	reads dst;
	int x,rst,limit=1;
	vector<int>sp;
	for (int i=2;i<=K;i<<=1)
	{
		num[i]=++length,rst=fast_pow(g,(mod-1)/i);
		for (int j=0,res=1;j<i;++j,res=1ll*res*rst%mod) wn[num[i]][j]=res;
		rst=fast_pow(g,(mod-1)/i*(i-1));
		for (int j=0,res=1;j<i;++j,res=1ll*res*rst%mod) wn2[num[i]][j]=res;
	}
	n=read(),m=read(),p=read(),L=read(),R=read(),e.d[0]=1,nw.d[1]=nw.d[(m<<1)-1]=1ll*p*MD2(1-p)%mod,nw.d[0]=MD(1ll*p*p%mod+1ll*MD2(1-p)*MD2(1-p)%mod);
	for (int i=1;i<=n;++i) x=read(),cnt[x]++;
	while (limit<=(m<<1)) limit<<=1;
	for (int i=0;i<m;++i) A[i]=cnt[i],B[m-i]=cnt[i];
	NTT(limit,A,1),NTT(limit,B,1);
	for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
	NTT(limit,A,-1);
	for (int i=1;i<m;++i) nws.d[i]=A[m+i];
	dst=nws*fast_pow(nw,L);
	while (limit<=(m<<2)) limit<<=1;
	for (int i=0;i<=limit;++i) A[i]=B[i]=0;
	for (int i=1;i<m;++i) A[i]=min(i,m-i);
	for (int i=1;i<m;++i) A[i+m]=MD2(-min(i,m-i));
	for (int i=0;i<(m<<1);++i) B[(m<<1)-i]=dst.d[i];
	NTT(limit,A,1),NTT(limit,B,1);
	for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
	NTT(limit,A,-1);
	for (int i=0;i<(m<<2);++i) Adder(dp[i%(m<<1)],A[i]);
	sp.resize(((R-L+1)<<1)+1);
	for (int i=0;i<=((R-L+1)<<1);++i) sp[i]=dp[(i-(R-L+1)%(m<<1)+(m<<1))%(m<<1)];
	T.build(1,1,R-L+1),T.solve(1,sp);
	for (int i=1;i<=R-L+1;++i) printf("%d ",res[i]);
	puts("");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 116ms
memory: 129180kb

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:

107146521 488242901 833543364 942893118 320285439 306745340 85380418 480027337 540734953 491950738 458848527 302817505 548924517 963679504 322777659 657420416 538451400 200569821 907146642 940780727 947566362 523285833 942400409 151786157 800926749 797312944 150412848 483203343 637066163 296999542 7...

result:

ok 7500 numbers

Test #2:

score: 0
Accepted
time: 112ms
memory: 126716kb

input:

7500 7499 673240178 1 7499
5325 2885 1225 7126 4988 4269 658 4221 3543 5162 3938 4780 143 2660 6991 5150 5888 6531 6373 6826 2873 5241 5052 793 5475 6299 3991 2399 5665 3786 7339 2749 1696 2681 583 936 5639 6299 4560 3177 6767 3089 4368 4458 650 6558 504 6277 5953 486 6093 1002 7466 5944 952 1796 26...

output:

109401794 751123382 342076416 876406297 327121602 311591650 658676729 820335019 101216944 433427180 230881034 816626094 344216982 198597590 550358617 514078855 683479653 690443997 798617649 473086234 4628208 388804376 899390057 607945374 81999043 497907004 96630466 310290755 759301009 878290881 3611...

result:

ok 7499 numbers

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 5
Accepted
time: 113ms
memory: 126740kb

input:

100000 7500 118222194 1 7500
3879 2242 3106 4127 506 5025 480 5913 2013 3740 650 2202 1577 2978 6555 6199 5338 381 936 7430 993 4028 5741 6540 6422 4252 2131 7437 5068 987 4811 7124 6065 6410 2109 6632 1991 995 78 4504 4427 2610 5727 3929 1822 1439 1017 4818 7129 5473 5854 3349 5040 4434 7465 3155 1...

output:

282177948 793195087 371410272 216302166 754838287 635906627 439235084 549238170 147552281 407585707 39424623 564372511 864932973 510959225 287498668 535739056 868188763 901535442 654683909 226988238 902028211 161262841 221883186 568157461 482406651 216671554 376345332 170647927 14316551 761201715 90...

result:

ok 7500 numbers

Test #4:

score: 0
Accepted
time: 112ms
memory: 126848kb

input:

100000 7499 747110152 1 7499
5187 1708 2112 4578 2265 288 4560 2351 944 4258 6394 3390 697 4182 532 833 82 3658 533 5870 5590 3592 6478 144 3929 4926 1845 2566 1063 4570 4748 5802 34 1128 876 3815 2323 4979 1508 4139 4002 4135 5945 611 1844 2457 6689 3266 6857 6852 2214 3486 5429 5273 1659 3586 7195...

output:

66587322 285203560 2811948 574520751 858297444 536639754 74432038 182648309 281510238 841004083 735652999 528557891 469508052 915681980 763925994 45174777 229418630 803369770 610703721 893113152 894067444 913745695 914305706 556012225 267456134 482474991 686056644 746085405 285733366 751933635 95587...

result:

ok 7499 numbers

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 242ms
memory: 125740kb

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:

961229471 

result:

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

Subtask #4:

score: 0
Skipped

Dependency #2:

100%
Accepted

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 473ms
memory: 128908kb

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:

504457332 

result:

wrong answer 1st numbers differ - expected: '397469689', found: '504457332'

Subtask #6:

score: 0
Skipped

Dependency #2:

100%
Accepted

Dependency #5:

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%