QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358644#971. Binary Search TreewdnmdwrnmmpAC ✓678ms64480kbC++143.4kb2024-03-19 21:52:282024-03-19 21:52:30

Judging History

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

  • [2024-03-19 21:52:30]
  • 评测
  • 测评结果:AC
  • 用时:678ms
  • 内存:64480kb
  • [2024-03-19 21:52:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;

const int N=2e5+5;
int n,m;
vi qry[N];
vector<vi> msg;
int lis[N],cntlis;
int ans[N];
int vis[N];
#define ls (d*2)
#define rs (d*2+1)
#define mid ((l+r)/2)
struct sgt{
	int mn[N*4],lsum[N*4],rsum[N*4];
	sgt(){
		fill(mn,mn+N*4,N-1);
	}
	int qlsum(int d,int l,int r,int cmn){
		if(l==r){
			return mn[d]<cmn?lis[l]:0;
		}
		if(cmn<mn[ls]){
			return qlsum(rs,mid+1,r,cmn);
		}
		else{
			return qlsum(ls,l,mid,cmn)+lsum[d]-lsum[ls];
		}
	}
	int qrsum(int d,int l,int r,int cmn){
		if(l==r){
			return mn[d]<cmn?lis[l]:0;
		}
		if(cmn<mn[rs]){
			return qrsum(ls,l,mid,cmn);
		}
		else{
			return qrsum(rs,mid+1,r,cmn)+rsum[d]-rsum[rs];
		}
	}
	void pushup(int d,int l,int r){
		mn[d]=min(mn[ls],mn[rs]);
		lsum[d]=lsum[ls]+qlsum(rs,mid+1,r,mn[ls]);
		rsum[d]=rsum[rs]+qrsum(ls,l,mid,mn[rs]);
	}
	void ins(int d,int l,int r,int nd,int nw){
		if(l==r){
			mn[d]=nw;
			lsum[d]=rsum[d]=lis[l];
			return;
		}
		if(nd<=mid){
			ins(ls,l,mid,nd,nw);
		}
		else{
			ins(rs,mid+1,r,nd,nw);
		}
		pushup(d,l,r);
	}
	void qL(int d,int l,int r,int nl,int nr,int &cmn,int &ans){
		if(nl<=l && r<=nr){
			ans+=qlsum(d,l,r,cmn);
			cmn=min(cmn,mn[d]);
			return;
		}
		if(nl<=mid){
			qL(ls,l,mid,nl,nr,cmn,ans);
		}
		if(nr>mid){
			qL(rs,mid+1,r,nl,nr,cmn,ans);
		}
	}
	void qR(int d,int l,int r,int nl,int nr,int &cmn,int &ans){
		if(nl<=l && r<=nr){
			ans+=qrsum(d,l,r,cmn);
			cmn=min(cmn,mn[d]);
			return;
		}
		if(nr>mid){
			qR(rs,mid+1,r,nl,nr,cmn,ans);
		}
		if(nl<=mid){
			qR(ls,l,mid,nl,nr,cmn,ans);
		}
	}
}T;
#undef ls
#undef rs
#undef mid

signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin>>n>>m;
	rep(i,1,m){
		int op; cin>>op;
		if(op==1){
			ans[i]=-1;
			int l,r,w; cin>>l>>r>>w;
			qry[i]={0,l,r,w};
			lis[++cntlis]=w;
		}
		else{
			int p,w; cin>>p>>w;
			qry[i]={1,p,w};
			lis[++cntlis]=w;
		}
	}
	sort(lis+1,lis+cntlis+1);
	cntlis=unique(lis+1,lis+cntlis+1)-lis-1;
	rep(i,1,m){
		if(qry[i][0]==0){
			qry[i][3]=lower_bound(lis+1,lis+cntlis+1,qry[i][3])-lis;
		}
		else{
			qry[i][2]=lower_bound(lis+1,lis+cntlis+1,qry[i][2])-lis;
		}
	}
	rep(i,1,m){
		if(qry[i][0]==0){
			msg.pb((vi){qry[i][1],0,qry[i][3],i});
			msg.pb((vi){qry[i][2]+1,1,qry[i][3],i});
		}
		else{
			msg.pb((vi){qry[i][1],2,qry[i][2],i});
		}
	}
	sort(msg.begin(),msg.end());
	
	fill(vis,vis+N,N-1);
	int p=0;
	rep(i,1,n){
		while(p<(int)msg.size() && msg[p][0]==i){
			if(msg[p][1]==0){
				vis[msg[p][2]]=msg[p][3];
				// cout<<"+"<<msg[p][2]<<' '<<msg[p][3]<<endl;
				T.ins(1,1,cntlis,msg[p][2],msg[p][3]);
			}
			else if(msg[p][1]==1){
				vis[msg[p][2]]=N-1;
				// cout<<"+"<<msg[p][2]<<' '<<N-1<<endl;
				T.ins(1,1,cntlis,msg[p][2],N-1);
			}
			else{
				int tmp=msg[p][3];
				T.qR(1,1,cntlis,1,msg[p][2],tmp,ans[msg[p][3]]);
				// cout<<"?"<<msg[p][2]<<' '<<msg[p][3]<<' '<<ans[msg[p][3]]<<endl;
				tmp=msg[p][3];
				T.qL(1,1,cntlis,msg[p][2],cntlis,tmp,ans[msg[p][3]]);
				if(vis[msg[p][2]]<msg[p][3]){
					ans[msg[p][3]]-=lis[msg[p][2]];
				}
			}
			p++;
		}
	}
	rep(i,1,m){
		if(ans[i]!=-1){
			cout<<ans[i]<<'\n';
		}
	}
	
}

詳細信息

Test #1:

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

input:

3 9
1 1 2 2
1 1 3 1
1 2 3 3
2 1 2
2 1 4
2 2 2
2 2 4
2 3 2
2 3 4

output:

2
2
2
5
4
4

result:

ok 6 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 16132kb

input:

463 469
1 133 459 764026743
2 183 117202921
1 158 440 909903500
2 435 764026743
2 211 764026743
2 42 367154098
1 69 368 922135695
2 402 822018114
1 202 356 216161481
2 164 868998762
2 241 425329855
2 418 359511579
1 93 193 705174793
1 152 400 189968120
2 249 216161481
2 203 705174793
2 163 705174793...

output:

764026743
764026743
764026743
0
1673930243
1673930243
980188224
764026743
980188224
980188224
1469201536
980188224
1318123566
866824493
0
1170156344
1673930243
1318123566
1377402832
1377402832
2181407311
3600267814
1170156344
2973487440
2973487440
2596065938
2730635983
4722051084
1802391517
11505832...

result:

ok 244 tokens

Test #3:

score: 0
Accepted
time: 2ms
memory: 16404kb

input:

484 474
1 406 463 109881109
2 85 109881109
1 71 279 296583468
1 315 405 845762420
2 115 135758925
1 128 426 231832375
2 89 231832375
1 167 337 318859441
1 25 470 274413310
1 96 390 756372223
1 61 295 165754375
1 35 172 978585214
2 419 41174840
2 117 294153522
1 251 451 944227634
2 236 521058490
1 21...

output:

0
296583468
296583468
109881109
570996778
1371815132
1328522053
2444444094
845762420
345295930
2255904798
2444444094
765052838
1328522053
2444444094
3200132432
4050100321
736751153
2031540905
1848365562
2031540905
1328522053
1371815132
2607571312
1710265211
2839403687
1371815132
2575413683
127516868...

result:

ok 247 tokens

Test #4:

score: 0
Accepted
time: 0ms
memory: 16232kb

input:

470 497
1 213 315 688950079
2 182 935243607
2 284 759121488
1 17 412 380215020
2 85 579963660
1 181 196 334962150
2 370 192806152
2 215 224781692
2 131 872288452
2 337 26050024
1 114 431 814931189
2 52 669029567
2 249 380215020
2 309 441395068
1 1 274 975212452
1 183 246 274176464
2 53 334962150
2 2...

output:

0
688950079
380215020
380215020
1069165099
380215020
380215020
380215020
1069165099
1069165099
380215020
1069165099
1503881268
380215020
1355427472
1965561652
1965561652
1209360140
3103822294
1374266992
3264103557
2243231610
2507101297
380215020
1374266992
975212452
1444751791
4032072871
975212452
7...

result:

ok 247 tokens

Test #5:

score: 0
Accepted
time: 0ms
memory: 16188kb

input:

493 463
2 45 257485474
2 159 328451300
2 86 755935133
1 109 314 662788126
1 105 137 652307266
1 220 230 585078539
1 40 152 987732902
1 403 453 701143316
2 311 662788126
2 137 144772224
1 19 469 660871707
1 261 488 561462797
2 106 532966299
1 185 447 301674848
2 376 585078539
1 132 230 930489923
1 17...

output:

0
0
0
662788126
1315095392
652307266
1222334504
1323659833
1315095392
1602523819
1315095392
1623022004
2004107238
0
1902781909
2904760316
2071757535
2064739823
2440820492
1602523819
1923477820
3447171476
2415300834
2618238422
4416419392
561462797
2440820492
2343297519
3687668206
1741013550
248258922...

result:

ok 236 tokens

Test #6:

score: 0
Accepted
time: 0ms
memory: 16432kb

input:

457 470
1 292 453 720075728
2 452 720075728
2 216 720075728
2 391 905797884
2 164 509201732
1 158 411 33220056
2 258 364791470
1 240 445 997195517
2 249 889854506
1 66 234 672803045
1 93 131 525803264
1 59 390 995582144
2 112 730128063
2 352 627612593
2 104 776864255
2 312 476638972
2 114 997195517
...

output:

720075728
0
720075728
0
33220056
1030415573
1668385189
753295784
1668385189
753295784
1668385189
720075728
720075728
1094109080
891677608
2494182634
1127329136
1914311192
1094109080
730721935
3475630869
1388507928
753295784
4169321965
720075728
500130774
2242082083
3256960114
672803045
2254587663
17...

result:

ok 245 tokens

Test #7:

score: 0
Accepted
time: 0ms
memory: 16408kb

input:

486 482
1 189 420 13562978
1 71 98 497680109
1 386 439 26860959
2 126 819724475
1 155 187 417451673
2 105 190622777
1 33 412 259382111
1 68 249 985928578
2 206 26860959
2 113 985928578
1 252 413 690032059
2 82 746894278
2 107 985928578
1 37 141 971858690
1 75 269 804759571
2 146 955713461
2 435 9718...

output:

0
0
272945089
1245310689
1483608687
1245310689
2050070260
26860959
962977148
272945089
962977148
989838107
1653135748
1959236505
1231240801
797587416
2829833337
448755906
259382111
2565781273
2565781273
1671737963
711397853
1178957167
259382111
1245310689
299806048
4236840922
4012233640
5008510123
5...

result:

ok 228 tokens

Test #8:

score: 0
Accepted
time: 6ms
memory: 16468kb

input:

456 485
1 284 381 243870266
2 294 243870266
2 221 333824628
2 344 257955215
1 169 390 555342089
1 412 451 890170638
1 134 215 413822665
1 227 248 467839622
1 416 438 482783488
1 43 226 690625572
2 80 690625572
1 14 93 242409105
1 317 421 812041726
1 60 170 30827120
1 6 93 112859626
1 78 423 43382958...

output:

243870266
0
243870266
690625572
1233041940
413822665
933034677
1245871311
444649785
799212355
444649785
1402994339
690625572
989171674
1155282277
1806783711
1689029006
3510858505
1155282277
1366864262
1245871311
1956572557
890170638
1233041940
3068360617
435895503
435895503
0
1427470248
1870249657
8...

result:

ok 245 tokens

Test #9:

score: 0
Accepted
time: 518ms
memory: 55872kb

input:

200000 200000
1 51313 114521 555056623
2 68565 479879347
2 160321 237655796
2 19629 323877634
1 74786 100241 586157367
1 79239 127700 292087607
2 160601 753692216
2 59935 594282500
2 199881 669670954
2 176742 478253487
2 58315 264892384
2 113864 836807945
2 191556 390162169
2 167124 883288716
1 4460...

output:

555056623
0
0
0
555056623
0
0
555056623
555056623
0
0
0
0
0
722918923
722918923
0
0
2833103567
968970654
1093577941
1215404365
3770087344
968970654
1277975546
1479485776
1093577941
1365240576
1111979640
4662965462
1111979640
81436293
1691889577
1584895623
1690533369
3770087344
1093577941
960688644
1...

result:

ok 100000 tokens

Test #10:

score: 0
Accepted
time: 267ms
memory: 41912kb

input:

200000 200000
2 94215 513319602
2 1176 117102044
2 181501 966490616
2 176617 402557165
2 27370 853611260
2 22211 12037731
2 162028 172866946
2 133426 573067240
2 145092 515765055
2 166059 204135617
2 135852 25575048
2 1837 397823360
2 99842 599957916
2 27523 398547296
2 27869 843297418
2 107494 5641...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 199900 tokens

Test #11:

score: 0
Accepted
time: 678ms
memory: 64480kb

input:

200000 200000
1 127950 193540 935545942
1 189440 190158 729551837
1 62857 119213 837264991
1 132519 148959 125766745
1 33229 81639 268951386
1 9463 91602 165627488
1 1525 71111 425080822
1 150182 191759 175255108
1 79455 119007 524444494
1 154893 166018 485699004
1 111658 141242 149759835
1 71643 96...

output:

707450694
8213350416
9024201226
1311461396
4528731386
9573074920
14797584372
5003543880
13046984674
7168329131
14306216062
4461150669
4555963051
12557676360
11174445890
3906033236
7613458168
9940604226
3055680653
8070176831
5994428170
7245015227
13409638878
14431145558
14267046265
14276682538
258380...

result:

ok 100 tokens

Test #12:

score: 0
Accepted
time: 499ms
memory: 55784kb

input:

200000 200000
2 119016 236789749
1 83 199029 108567257
2 169818 163281875
2 10238 5752673
1 468 199152 145551572
1 801 199683 897743813
1 4 199815 523438729
2 162775 263324119
1 711 199933 347795549
2 156957 248308862
2 147094 754712526
1 94 199323 250957293
2 197246 9999436
2 15011 873805051
1 453 ...

output:

0
108567257
108567257
1675301371
2023096920
1675301371
108567257
1675301371
2514007470
2274054213
2274054213
2514007470
2023096920
2274054213
2023096920
2274054213
3263794482
3263794482
3263794482
3263794482
2023096920
395984696
2514007470
2023096920
2023096920
2274054213
516401360
395984696
4072412...

result:

ok 100000 tokens

Test #13:

score: 0
Accepted
time: 324ms
memory: 55820kb

input:

200000 200000
2 134521 901986931
1 1 200000 550103434
1 1 200000 971671841
1 1 200000 942493350
2 29335 875123547
1 1 200000 558507112
1 1 200000 914437913
1 1 200000 829138829
1 1 200000 835881439
2 179046 314018872
2 76228 273248837
2 113816 700216405
2 168503 990187806
1 1 200000 712590545
1 1 20...

output:

0
2464268625
550103434
550103434
4766352479
1521775275
6037905698
6037905698
6441082010
3022775737
1931538186
6208123719
1931538186
6441082010
3433225655
1931538186
1931538186
6208123719
6208123719
4872801910
2227236572
1050384441
2422185320
2422185320
1494530179
6609991584
6208123719
2422185320
651...

result:

ok 100000 tokens

Test #14:

score: 0
Accepted
time: 618ms
memory: 63620kb

input:

200000 200000
1 78168 171119 1958
1 80444 149874 11768
1 56846 156923 13406
1 83143 184925 17882
1 12565 163196 21847
1 10704 197187 33248
1 94918 129949 35892
1 37100 168273 37178
1 49859 166583 40976
2 15399 713882729
1 33859 137898 43679
1 40673 137429 46146
1 67914 151456 48446
1 49683 164460 58...

output:

55095
460006
0
19633120
17727329
87698206
55933795
67332525
127268752
6029963
71925438
5396213
33463719
98351104
199105683
125519423
10131862
236146848
0
168445792
8874230
440924569
458386493
331038510
545258701
83165472
221451191
64845852
292666250
623280369
743856895
121231190
527548256
463760643
...

result:

ok 10000 tokens

Test #15:

score: 0
Accepted
time: 621ms
memory: 63616kb

input:

200000 200000
1 5520 199378 999994999
1 3561 196227 999981541
1 8986 192575 999975739
1 9648 192417 999974741
1 5985 194355 999973599
1 8039 190033 999967787
1 3868 198209 999962646
1 2627 193683 999962333
1 8105 193561 999953290
1 7653 196980 999944743
1 5210 198551 999940586
1 6095 197532 99993674...

output:

17999066991
23736404052
7737422358
23736404052
37734127593
24218949120
12219783478
24514116566
95613169057
24514116566
96438659702
95613169057
24514116566
25187167263
25187167263
26040947724
25520398204
25503344002
26040947724
95613169057
3550585863
81615902304
25971562998
48885213006
26058535763
26...

result:

ok 10000 tokens

Test #16:

score: 0
Accepted
time: 514ms
memory: 55856kb

input:

200000 200000
2 160547 842350992
2 67014 443099976
2 63168 86066200
2 168437 924227232
2 159000 479779285
1 61568 199136 984363344
2 9952 745313897
2 55794 51205764
2 68840 994631863
2 151784 469771583
1 16303 156377 142426625
2 149321 210014038
2 107873 586153542
1 37809 79925 532
2 30139 15140317
...

output:

0
0
0
0
0
0
0
984363344
984363344
1126789969
1126789969
142426625
1126790501
2027198244
854506623
2447303172
2447303172
2447303172
0
2447303172
3076265655
2013853155
854506623
3076265655
1884771619
2964429523
2964429523
2447303172
2013853155
2447303172
1060627232
1060627232
1547550784
1905688591
205...

result:

ok 100000 tokens