QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204339#7438. 樋口円香zhouhuanyiAC ✓1638ms64252kbC++233.0kb2023-10-07 10:15:222023-10-07 10:15:23

Judging History

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

  • [2023-10-07 10:15:23]
  • 评测
  • 测评结果:AC
  • 用时:1638ms
  • 内存:64252kb
  • [2023-10-07 10:15:22]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cmath>
#define N 100000
#define M 1000000
#define S 262144
#define K 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;
}
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 MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
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 n,m,sz,length,rev[S+1],a[N+1],b[N+1],block[N+1],sl[M+1],sr[M+1],sL[M+1],A[S+1],B[S+1],C[S+1],num[S+1],wn[K+1][S+1],wn2[K+1][S+1];
void NTT(int limit,int *s,int type)
{
	int s1,s2;
	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);
		s1=fast_pow(limit,mod-2);
		for (int i=0;i<=limit;++i) s[i]=1ll*s[i]*s1%mod;
	}
	return;
}
void adder(int l,int r,int d)
{
	for (int i=l;i+7<=r;i+=8)
	{
		b[i+d]+=a[i];
		b[i+1+d]+=a[i+1];
		b[i+2+d]+=a[i+2];
		b[i+3+d]+=a[i+3];
		b[i+4+d]+=a[i+4];
		b[i+5+d]+=a[i+5];
		b[i+6+d]+=a[i+6];
		b[i+7+d]+=a[i+7];
	}
	for (int i=1;i<=((r-l+1)&7);++i) b[r-i+1+d]+=a[r-i+1];
	return;
}
int main()
{
	int limit=1,l,r,L,w;
	bool op;
	for (int i=2;i<=S;i<<=1)
	{
		num[i]=++length,w=fast_pow(g,(mod-1)/i);
		for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*w%mod) wn[num[i]][j]=res;
		w=fast_pow(g,(mod-1)/i*(i-1));
		for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*w%mod) wn2[num[i]][j]=res;
	}
	n=read();
	for (int i=1;i<=n;++i) a[i]=read();
	m=read(),sz=3125;
	while (limit<=sz+n) limit<<=1;
	for (int i=1;i<limit;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?limit>>1:0);
	for (int i=1;i<=n;++i) block[i]=(i-1)/sz+1;
	for (int i=1;i<=m;++i)
	{
		l=sl[i]=read(),r=sr[i]=read(),L=sL[i]=read(),r=sr[i]=min(r,n-L+l);
		if (block[r]-block[l]<=1) adder(l,r,L-l);
		else adder(l,min(block[l]*sz,n),L-l),adder((block[r]-1)*sz+1,r,L-l);
	}
	for (int i=1;i<=block[n];++i)
	{
		op=0;
		for (int j=0;j<=limit;++j) A[j]=B[j]=0;
		for (int j=(i-1)*sz+1;j<=min(i*sz,n);++j) A[j-(i-1)*sz]=a[j];
		for (int j=1;j<=m;++j)
		{
			l=sl[j],r=sr[j],L=sL[j];
			if (block[l]+1<=i&&i<=block[r]-1) B[(i-1)*sz-l+L]++,op=1;
		}
		if (!op) continue;
		NTT(limit,A,1),NTT(limit,B,1);
		for (int j=0;j<=limit;++j) Adder(C[j],1ll*A[j]*B[j]%mod);
	}
	NTT(limit,C,-1);
	for (int i=1;i<=n;++i) b[i]+=C[i];
	for (int i=1;i<=n;++i) printf("%d\n",b[i]);
	puts("");
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 55152kb

input:

1000
629 353 463 242 579 37 341 579 751 331 971 209 993 230 150 893 723 872 154 456 443 858 815 904 643 97 471 510 695 436 306 499 371 971 494 147 702 903 795 968 731 890 594 590 356 63 313 564 718 680 525 284 848 154 36 858 367 454 723 351 580 80 102 308 680 598 185 681 706 494 725 951 248 570 793 ...

output:

9812
18329
25519
40685
50358
58477
67055
71202
84917
83471
95554
98972
114054
112482
126642
125010
144914
147671
141407
162102
164317
170828
171245
193368
183842
180062
189229
195363
201525
208055
211890
218246
222774
237496
232051
230084
240108
247492
257506
259433
262038
254605
259817
258900
25715...

result:

ok 1000 lines

Test #2:

score: 0
Accepted
time: 333ms
memory: 58208kb

input:

100000
984 353 333 932 661 754 360 57 828 818 156 676 408 992 550 847 743 689 198 782 144 163 27 320 781 316 966 842 84 797 588 39 867 498 675 598 345 159 491 1000 46 874 992 829 838 575 542 836 541 30 393 998 762 434 978 382 34 862 446 828 283 820 537 293 597 240 198 258 404 929 977 588 138 214 504...

output:

11337
20492
27617
38150
59067
68173
78360
91299
95892
109338
125673
129644
134532
153938
162487
181716
190109
202080
211662
217170
233126
223881
247707
269064
262512
271414
292008
286305
310010
326696
327857
340549
356849
355034
385112
396461
394276
401687
431908
429402
436902
456239
480823
466472
4...

result:

ok 100000 lines

Test #3:

score: 0
Accepted
time: 1638ms
memory: 61152kb

input:

100000
770 158 194 936 605 941 814 119 685 202 611 549 697 350 322 412 751 477 433 316 489 211 428 467 47 155 318 646 342 664 801 700 466 584 494 455 350 801 315 65 323 248 952 506 429 320 798 591 272 702 475 708 457 911 421 957 642 737 75 483 938 415 371 945 792 88 400 928 125 850 140 313 121 4 784...

output:

371669
747329
1146914
1544890
1951278
2344214
2671548
3011240
3361942
3682875
4053079
4355837
4673991
4995561
5351185
5649899
5988989
6396368
6630334
6926213
7229448
7600320
7823165
8256958
8525065
8836172
9164533
9645612
9980857
10304819
10655807
10957867
11309644
11491081
11842439
12131144
1247762...

result:

ok 100000 lines

Test #4:

score: 0
Accepted
time: 1435ms
memory: 64252kb

input:

100000
353 321 823 423 572 507 218 465 497 519 453 452 684 21 764 867 981 119 152 830 536 866 685 8 579 68 965 889 531 709 207 766 160 771 412 231 480 238 284 517 17 432 383 379 762 272 612 589 196 46 911 165 710 748 2 18 943 270 484 316 935 518 496 886 747 989 398 604 722 383 537 818 591 347 149 32...

output:

10674
22292
36969
47709
49953
58490
62009
74704
86454
95951
102377
116026
122769
138788
145124
163696
177331
167829
188244
187890
217197
216718
229361
234397
253240
258627
267010
271325
286377
283180
301260
313803
332054
342858
346379
368019
377504
381487
408040
413169
416129
411884
417746
435234
45...

result:

ok 100000 lines