QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#570292#9311. Protection WarLateRegistration#AC ✓1046ms31928kbC++204.6kb2024-09-17 15:11:512024-09-17 15:11:53

Judging History

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

  • [2024-09-17 15:11:53]
  • 评测
  • 测评结果:AC
  • 用时:1046ms
  • 内存:31928kb
  • [2024-09-17 15:11:51]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
const int B=1000;
int laz[300005],het[300005],zh[300005];
int bh[300005];
int bl[300005],br[300005];
void changed(int x,int k)
{
	zh[x]+=k;
	het[bh[x]]+=k;
}
int queryd(int x)
{
	return zh[x]+laz[bh[x]];
}
void change(int l,int r,int k)
{
	if(l>r)return;
	if(bh[l]==bh[r])
	{
		for(int i=l;i<=r;i++)zh[i]+=k,het[bh[i]]+=k;
		return;
	}
	for(int i=l;i<=br[bh[l]];i++)zh[i]+=k,het[bh[i]]+=k;
	for(int i=bh[l]+1;i<=bh[r]-1;i++)laz[i]+=k,het[i]+=k*(br[i]-bl[i]+1);
	for(int i=bl[bh[r]];i<=r;i++)zh[i]+=k,het[bh[i]]+=k;
}
int query(int l,int r)
{
	if(l>r)return 0;
	if(bh[l]==bh[r])
	{
		int ans=0;
		for(int i=l;i<=r;i++)ans+=zh[i]+laz[bh[i]];
		return ans;
	}
	int ans=0;
	for(int i=l;i<=br[bh[l]];i++)ans+=zh[i]+laz[bh[i]];
	for(int i=bh[l]+1;i<=bh[r]-1;i++)ans+=het[i];
	for(int i=bl[bh[r]];i<=r;i++)ans+=zh[i]+laz[bh[i]];
	return ans;
}
int dl[300005],dr[300005],dh[300005],dlaz[300005],cnt;
int nl[300005],nr[300005],nh[300005],nlaz[300005],ncnt;
int a[300005];
signed main()
{
	int n,q,opt,x,y,z;
	n=read();
	q=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		bh[i]=(i-1)/B+1;
		if(bl[bh[i]]==0)bl[bh[i]]=i;
		br[bh[i]]=i;
	} 
	for(int i=1;i<=n;i++)changed(i,a[i]);
	cnt=1;
	dl[1]=1;
	dr[1]=n;
	dlaz[1]=0;
	for(int i=1;i<=n;i++)dh[1]+=a[i];
	int dflag=0;
	for(int cs=1;cs<=q;cs++)
	{
		dflag=0;
		opt=read();
		if(opt==1)
		{
			x=read();
			y=read();
			if(y!=0)
			{
				int sth=queryd(x);
				for(int i=1;i<=cnt;i++)if(dl[i]<=x&&dr[i]>=x)sth+=dlaz[i];
				opt=2;
				z=y-sth;
				y=x;
				dflag=1;
				//changed(x,y-sth);
				//for(int i=1;i<=cnt;i++)if(dl[i]<=x&&dr[i]>=x)dh[i]+=y-sth;
				//continue;
			}
			else
			{ 
			int sth=queryd(x);
			for(int i=1;i<=cnt;i++)if(dl[i]<=x&&dr[i]>=x)sth+=dlaz[i];
			changed(x,-sth);
			ncnt=0;
			for(int i=1;i<=cnt;i++)
			{
				if(dl[i]<=x&&dr[i]>=x)
				{
					change(dl[i],dr[i],dlaz[i]);
					if(dl[i]<x)
					{
						nl[++ncnt]=dl[i];
						nr[ncnt]=x-1;
						nlaz[ncnt]=0;
						nh[ncnt]=query(dl[i],x-1);
					}
					if(dr[i]>x)
					{
						nl[++ncnt]=x+1;
						nr[ncnt]=dr[i];
						nlaz[ncnt]=0;
						nh[ncnt]=query(x+1,dr[i]);
					}
				}
				else
				{
					nl[++ncnt]=dl[i];
					nr[ncnt]=dr[i];
					nh[ncnt]=dh[i];
					nlaz[ncnt]=dlaz[i];
				}
			}
			cnt=ncnt;
			for(int i=1;i<=cnt;i++)
			{
				dl[i]=nl[i];
				dr[i]=nr[i];
				dh[i]=nh[i];
				dlaz[i]=nlaz[i];
			}
			}
		}
		if(opt==2)
		{
			if(!dflag)
			{
			x=read();
			y=read();
			z=read();
		}
			int tl=x,tr=y;
			for(int i=1;i<=cnt;i++)
			{
				if(dl[i]<=x-1&&dr[i]>=x-1)tl=min(tl,dl[i]);
				if(dl[i]<=y+1&&dr[i]>=y+1)tr=max(tr,dr[i]);
			}
			change(x,y,z);
			ncnt=0;
			for(int i=1;i<=cnt;i++)
			{
				if(dr[i]<x-1||dl[i]>y+1)
				{
					nl[++ncnt]=dl[i];
					nr[ncnt]=dr[i];
					nh[ncnt]=dh[i];
					nlaz[ncnt]=dlaz[i];				
				}
				else
				{
					change(dl[i],dr[i],dlaz[i]);
				}
			}
			nl[++ncnt]=tl;
			nr[ncnt]=tr;
			nh[ncnt]=query(tl,tr);
			nlaz[ncnt]=0;
			cnt=ncnt;
			for(int i=1;i<=cnt;i++)
			{
				dl[i]=nl[i];
				dr[i]=nr[i];
				dh[i]=nh[i];
				dlaz[i]=nlaz[i];
			}
		}
		else if(opt==3)
		{
			for(int i=1;i<=cnt;i++)dlaz[i]++,dh[i]+=(dr[i]-dl[i]+1);
		}
		else if(opt==4)
		{
			for(int i=1;i<=cnt;i++)dlaz[i]+=dr[i]-dl[i]+1,dh[i]+=(dr[i]-dl[i]+1)*(dr[i]-dl[i]+1);
		} 
		else if(opt==5)
		{
			x=read();
			y=read();
			int ans=0;
			for(int i=1;i<=cnt;i++)
			{
				if(dl[i]>=x&&dr[i]<=y)ans+=dh[i]; 
				else if(dr[i]<x||dl[i]>y)
				{
					//do nothing
				}
				else
				{
					int tl=max(dl[i],x),tr=min(dr[i],y);
					//for(int j=tl;j<=tr;j++)printf("???%d %d\n",j,query(j,j)+dlaz[i]);
					ans+=query(tl,tr)+dlaz[i]*(tr-tl+1);
				}
			}
			printf("%lld\n",ans);
		}
		ncnt=0;
		for(int i=1;i<=cnt;i++)
		{
			if(dr[i]==n)
			{
				nl[++ncnt]=dl[i];
				nr[ncnt]=dr[i];
				nh[ncnt]=dh[i];
				nlaz[ncnt]=dlaz[i];
				continue;
			}
			int sth=queryd(dr[i]);
			changed(dr[i],-sth);
			if(dl[i]<dr[i])
			{
				nl[++ncnt]=dl[i];
				nr[ncnt]=dr[i]-1;
				nh[ncnt]=dh[i]-sth-dlaz[i];
				nlaz[ncnt]=dlaz[i];
			}
		}
		cnt=ncnt;
		//printf("orz%lld\n",cs);
		for(int i=1;i<=cnt;i++)
		{
			dl[i]=nl[i];
			dr[i]=nr[i];
			dh[i]=nh[i];
			dlaz[i]=nlaz[i];
			//printf("%lld %lld %lld %lld\n",dl[i],dr[i],dh[i],dlaz[i]);
		}
		//printf("!!!\n");
	}
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 26496kb

input:

10 8
1 2 3 4 5 6 7 8 9 10
1 5 0
4
5 1 10
2 1 7 10
5 1 7
1 5 0
3
5 1 7

output:

74
97
71

result:

ok 3 number(s): "74 97 71"

Test #2:

score: 0
Accepted
time: 159ms
memory: 26320kb

input:

500 300000
20001 40132 29212 16930 79791 32181 87513 9436 61594 60199 23626 56049 76877 26228 46852 90808 52774 97868 84080 20953 39737 27635 93897 50290 59947 50049 48449 69397 73015 60257 27292 82311 2349 40210 30130 62403 95726 30729 28690 69685 48849 16781 91994 30976 22114 43258 99392 77848 384...

output:

1777087
6304031
39352977
61099409
15756683
31610555
44754327
12487869
59587103
2013274
3787120
9520811
30097273
0
29379053
97470237
16716946
10173160
60903053
77967400
42424120
82321580
1362621
19339692
48461160
173887621
191344136
26872842
98980145
89270173
54079590
73055561
53268415
64611723
21370...

result:

ok 60308 numbers

Test #3:

score: 0
Accepted
time: 160ms
memory: 26364kb

input:

500 300000
3661 36740 51832 61516 76116 24936 6180 33534 84366 8372 97227 47341 2526 19922 41191 86094 37721 71264 99337 54956 80744 56721 73555 85761 89738 85868 62174 27710 74319 38092 35510 44105 96574 35486 72952 53626 88784 66790 47099 37245 17138 48570 66404 18867 14727 93189 20368 208 92836 9...

output:

14046143
20948450
2866449
26237759
17432940
22077719
42448823
6203132
42995489
13023558
83271628
46227856
14594620
72259746
31434457
53554700
57705358
17165033
162671227
128280776
146609232
133716010
94318636
13656985
73755685
8630665
77502753
144457801
106411744
8636969
186415804
59188599
141850862...

result:

ok 59918 numbers

Test #4:

score: 0
Accepted
time: 696ms
memory: 27072kb

input:

300000 300000
57451 36906 78465 95706 19070 48873 54372 46322 22034 19942 23717 25586 79904 74145 51471 62558 50792 70621 4724 68730 47246 26210 7754 60498 54168 7614 62761 36563 92242 46335 69583 58448 61354 34810 64860 92478 82964 20840 36278 63608 90438 51236 50182 48955 68925 67502 90010 6315 60...

output:

24038355781
17520159076
77426274356
112236455136
233944213210
127898744311
175688445771
426885053349
239002345886
22295671469
136802216849
462348680839
382946706667
801141945001
573484605895
173524140651
14447679142
630305728424
9442569891
261017396115
1080207552674
110655277820
340172946827
1636415...

result:

ok 59603 numbers

Test #5:

score: 0
Accepted
time: 684ms
memory: 31928kb

input:

300000 300000
84215 66218 44189 40293 72291 413 40336 37716 44806 820 97317 49582 72849 67839 13106 66357 35739 11313 19982 2733 55549 31105 87412 4481 83959 10729 84999 27581 17737 48362 45097 87537 31387 5894 74978 7892 76021 56901 20096 31167 50215 83025 24593 79950 28835 84729 10986 61379 5950 1...

output:

211281268649
81904713663
107994432954
237079419347
158601219821
374047091474
216749096504
326901757608
269358863804
581445761431
301095611648
206331558554
334116145342
739321744537
93840133893
212593254720
813432938058
263696251557
385499825902
75141830842
74764348483
52704328099
212029381920
806844...

result:

ok 60164 numbers

Test #6:

score: 0
Accepted
time: 1046ms
memory: 27528kb

input:

300000 300000
7412 76492 94901 3626 78858 87917 49058 88554 92597 75867 27429 17150 46087 10141 39105 55151 34067 21758 7067 86217 65749 79659 86528 76796 45415 16470 84095 63419 53805 89782 83595 24384 44746 66757 53466 4838 91272 40992 89896 71278 65749 15979 31381 12347 82272 80779 48547 79990 90...

output:

13122639444
13095679258
13093395236
13087814669
13053282543
13052721576
13041630291
13016365397
13013741533
12997505496
12989617831
12979637756
12955892310
12951817252
12946528851
12920024861
12915843420
12896461225
12866329898
12869025185
12841320314
12844736862
12821848130
12792783793
12796548834
...

result:

ok 200292 numbers

Test #7:

score: 0
Accepted
time: 920ms
memory: 27520kb

input:

300000 300000
20669 5970 44154 49699 7737 4609 83214 25440 53037 2907 60224 19392 7898 58058 43723 2710 64789 94511 70816 42507 73258 54042 385 87004 39637 8627 98407 30586 73031 53 68990 67817 79559 37165 88196 67617 11214 41503 62893 32496 31530 50433 65378 6134 29084 72319 14973 32648 22138 88981...

output:

5698802159
10597939002
20813590627
31856754606
39835081021
41793891196
45218870046
50644631126
54266744131
64411670941
74554458218
82525404975
92433210740
98453810830
109008791781
115435658443
117013910344
123286748855
124904647545
133062330734
141173611755
147961748284
147725622076
153998524696
160...

result:

ok 434 numbers

Test #8:

score: 0
Accepted
time: 1036ms
memory: 28508kb

input:

300000 300000
75892 62519 12013 16206 17002 62157 32926 30574 51502 53705 26647 79704 92525 56344 96103 28812 26522 44166 69795 74921 69002 84617 31844 25364 67224 42294 75077 79672 89026 10025 35398 19521 65482 15138 87212 5120 35029 64355 21630 68362 60976 46483 24841 29209 50342 14269 48318 16073...

output:

13116000222
13094453151
13098642889
13087707456
13094719548
13076723577
13050683617
13016169111
13021901966
13009340083
12993202047
12962584048
12988522796
12946539906
12931665515
12938940148
12899518530
12917872557
12882217735
12861741083
12862089495
12868549968
12834345778
12822169096
12811629901
...

result:

ok 200289 numbers

Extra Test:

score: 0
Extra Test Passed