UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211242#2398. 游戏three_zero3000ms0kbC++111.1kb2024-08-10 08:50:482024-08-10 12:33:54

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m;
int op,s,l,r;
const int N=1e6+2;
ll sum[4*N],add[4*N];
void Add(int k,int l,int r,int v){
	add[k]+=v;
	sum[k]+=(r-l+1)*v;
	return ;
}
void pushdown(int k,int l,int r){
	if(add[k]==0)return ;
	int mid=(l+r)>>1;
	Add(k*2,l,mid,add[k]);
	Add(k*2+1,mid+1,r,add[k]);
	add[k]=0;
}
void modify(int k,int l,int r,int x,int y,int v){
	if(x<=l && y>=r){
		Add(k,l,r,v);
		return ;
	}
	int mid=(l+r)>>1;
	pushdown(k,l,r);
	if(x<=mid)modify(k*2,l,mid,x,y,v);
	if(y>mid)modify(k*2+1,mid+1,r,x,y,v);
	sum[k]=sum[k*2]+sum[k*2+1];
}
ll check(int k,int l,int r,int x,int y){
	if(x<=l && y>=r){
		return sum[k];
	}
	int mid=(l+r)>>1;
	ll res=0;
	pushdown(k,l,r);
	if(x<=mid)res+=check(k*2,l,mid,x,y);
	if(y>mid)res+=check(k*2+1,mid+1,r,x,y);
	return res;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	while(m--){
		cin>>op;
		if(op==1){
			cin>>s>>l>>r;
			for(int i=l;i<=r;i++)modify(1,1,n,i,r,s);
		}
		else{
			cin>>l>>r;
			cout<<check(1,1,n,l,r)<<endl;
		}
	}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Time Limit Exceeded

input:

10000 10000
2 7160 9968
1 -473 6964 8476
1 -153 5216 7023
2 6352 6868
1 -323 2338 2855
1 415 8414 88...

output:

0
-110345895
-118168581
-43417983
-4860827434
-604843653
-2613457133
-534205626
-89290630
484290874
...

result:


Test #2:

score: 0
Time Limit Exceeded

input:

10000 10000
1 326 2291 8264
2 2344 3512
1 146 4506 4804
1 342 1373 4495
1 -267 929 3525
1 444 3384 8...

output:

243137972
7529843014
0
11315350608
10741570136
-23729193
8497340876
11134190564
4752384896
166579811...

result:


Test #3:

score: 0
Time Limit Exceeded

input:

666666 10000
1 92 555251 586462
1 393 28541 523118
1 448 17256 369367
1 -28 89257 596132
1 -338 3136...

output:


result:


Test #4:

score: 0
Time Limit Exceeded

input:

666666 50000
1 -249 309981 333889
1 477 309512 463171
1 0 71655 592642
1 45 191249 527454
1 55 38872...

output:


result:


Test #5:

score: 0
Time Limit Exceeded

input:

666666 100000
1 -183 598736 630118
1 -337 605875 639236
1 -62 265069 340682
1 -96 370300 571646
1 -1...

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

666666 100000
2 121929 379928
2 34550 66844
1 96 338911 637923
2 161666 370147
1 -282 313713 463127
...

output:

0
0
46837507488
-2144565871356
12891851830
8888329560532
3600670974792
5838384797676

result:


Test #7:

score: 0
Time Limit Exceeded

input:

750000 100000
1 -318 454211 721481
2 239247 294171
2 52513 339575
2 424462 638364
2 683282 740790
1 ...

output:

0
0
-5392147899330
-3014688113400
-1060371486324
-3974117952270
273653038350
-222431173482
371388923...

result:


Test #8:

score: 0
Time Limit Exceeded

input:

1000000 100000
1 -108 318728 708230
1 -242 8738 411540
1 -119 458000 972357
2 368015 850304
1 -182 1...

output:

-21232196185685
-20910538239000
-3733012342070

result:


Test #9:

score: 0
Time Limit Exceeded

input:

1000000 100000
2 347033 984386
2 277881 323793
1 431 735974 973576
2 782909 863840
1 -22 379088 6406...

output:

0
0
3048712203338
-275350879342
2861261347158
10963743541855
980271778300
5329951205134
712899593630...

result:


Test #10:

score: 0
Time Limit Exceeded

input:

1000000 100000
1 -238 406279 814973
1 -425 637451 721356
1 237 340114 658854
2 279214 591961
2 17862...

output:

3413253435344
4249749642085
3270374154195
-7408047958251

result: