UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203783#151. Boomsnow_trace1008809ms50548kbC++113.8kb2024-03-19 09:22:322024-03-19 12:32:10

answer

#include<bits/stdc++.h>
using namespace std;
int head[100005],nxt[30000005],pos[30000005],add[30000005],id[30000005];
#define int long long
int p[2005],ad[2005],nw =0;
int pre[100005],ppre[100005],ans[100005];
int sq;int kpre[100005],npre[100005],be[100005],L[1005],R[1005],val[100005];
int tt =0 ;
int n,m;int l[100005],r[100005],a[100005];
int ll[100005],rr[100005];
void update(int rr){
	val[rr]++;
	for(int j = be[rr];j>=1;j--)kpre[j]++;
	npre[R[be[rr]]] = val[R[be[rr]]];
	for(int j = R[be[rr]]-1;j>=L[be[rr]];j--)npre[j] = val[j]+npre[j+1];
//	for(int j = 1;j<=sq;j++)cout << kpre[j] << " ";cout << endl;
//	for(int j = 1;j<=n;j++)cout << npre[j] << " ";cout << endl;
}
void init(){
	sq = sqrt(n);
	for(int i = 1;i<=sq;i++){
		L[i] = (i-1)*sq+1,R[i] = i*sq;
	}R[sq] = n;
	for(int i = 1;i<=sq;i++){
		for(int j = L[i];j<=R[i];j++)be[j] = i;
	}
}void clear_(){
	nw =0 ;
	for(int i = 1;i<=n;i++)pre[i] = pre[i-1]+a[i];
	for(int i = 1;i<=n;i++)ppre[i] = ppre[i-1]+pre[r[i]]-pre[l[i]-1];
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>> n;
	for(int i = 1;i<=n;i++)cin >> a[i];
	for(int i = 1;i<=n;i++)cin >> l[i] >> r[i]; 
	init();clear_();
	cin >> m;
	for(int i = 1;i<=m;i++){
		int op;cin>> op;
		if(op == 1){
			int x,y;cin >> x >> y;
			p[++nw] = x,ad[nw] = y-a[x];a[x] = y;
			if(nw == 102)clear_();
		}else{
			int l,r;cin >> l >> r;ll[i] = l,rr[i] = r;ans[i]=ppre[r]-ppre[l-1];
			for(int j = 1;j<=nw;j++){
				id[++tt] = i;add[tt] = ad[j];pos[tt] = p[j];
			}
		}
	}memset(head,-1,sizeof(head));
	for(int i = 1;i<=tt;i++){
		int ttt = rr[id[i]];
		nxt[i] = head[ttt];head[ttt] = i;
	//	cout << " " << ttt << " " << head[ttt] << " " << add[head[ttt]] << endl;
	}/*
	相当于一个二维前缀和,要做四遍 
	*/
	for(int i = 0;i<=n;i++)val[i] = kpre[i] = npre[i] = 0;
	for(int i = 1;i<=n;i++){
		int rr = r[i];
	//	cout << " " << rr << endl;
		update(rr);
		for(int x = head[i];x!=-1;x = nxt[x]){
			ans[id[x]]+=1ll*(kpre[be[pos[x]]+1]+npre[pos[x]])*add[x];
	//		cout<< "  " << id[x] << " " << pos[x] << " " <<  (kpre[be[pos[x]]+1]+npre[pos[x]])*add[x] <<" " << add[x]<< endl;
		}
	}for(int i =0;i<=n;i++)val[i] = kpre[i] = npre[i] =0 ;
	for(int i = 1;i<=n;i++){
		int rr = l[i]-1;
		if(rr!=0){
			update(rr);
		}for(int x = head[i];x!=-1;x = nxt[x]){
			ans[id[x]]-=1ll*(kpre[be[pos[x]]+1]+npre[pos[x]])*add[x];
	//		cout<< "  " << id[x] << " " << pos[x] << " " <<  (kpre[be[pos[x]]+1]+npre[pos[x]])*add[x] <<" " << add[x]<< endl;
		}
	}memset(head,-1,sizeof(head));
	for(int i = 1;i<=tt;i++){
		int ttt = ll[id[i]]-1;
		nxt[i] = head[ttt];head[ttt] = i;
	}for(int i =0;i<=n;i++)val[i] = kpre[i] = npre[i] =0 ;
	for(int i = 1;i<=n;i++){
		int rr = r[i];
		update(rr);
		for(int x = head[i];x!=-1;x = nxt[x]){
			ans[id[x]]-=1ll*(kpre[be[pos[x]]+1]+npre[pos[x]])*add[x];
	//		cout<< "  " << id[x] << " " << pos[x] << " " <<  (kpre[be[pos[x]]+1]+npre[pos[x]])*add[x] <<" " << add[x]<< endl;
		}
	}for(int i =0;i<=n;i++)val[i] = kpre[i] = npre[i] =0 ;
	for(int i = 1;i<=n;i++){
		int rr = l[i]-1;
		if(rr!=0){
			update(rr);
		}for(int x = head[i];x!=-1;x = nxt[x]){
			ans[id[x]]+=1ll*(kpre[be[pos[x]]+1]+npre[pos[x]])*add[x];
	//		cout<< "  " << id[x] << " " << pos[x] << " " <<  (kpre[be[pos[x]]+1]+npre[pos[x]])*add[x] <<" " << add[x]<< endl;
		}
	}for(int i = 1;i<=m;i++)if(rr[i]!=0)cout << ans[i] << '\n'; 
	return 0;
}/*
nsqrtlog做法:定期重构
nsqrt只需要离线下来分块平衡一下。
链式前向星似乎有莫名其妙的大常数(在noi.ac上)
不懂啊。 
我感觉每次模拟赛我都可以想出非正解的大常数大代码难度的愚蠢做法。 
10
2067261 384717275 17463453 888985702 138961334 1411632 688969676 74515292 188541827 77102447
2 5
3 9
5 10
8 8
1 2
 3 10
 4 4
 2 3
1 5
2 4
5
1 8 604985272
1 1 800602979
1 7 927577929
2 2 7
2 6 8
*/

详细

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

Subtask #1:

score: 15
Accepted

Test #1:

score: 15
Accepted
time: 0ms
memory: 2188kb

input:

978
622650072 984943658 144108929 470211272 101027544 457850877 458777922 7237707 823564440 11543816...

output:

40338284513108
71903057781631
95881406749369
32494373280638
25239917056405
77776995079159
8929433735...

result:

ok 476 numbers

Test #2:

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

input:

955
97816498 969887315 140734213 940422544 202055088 768218109 770072199 866991770 647128879 8339268...

output:

5909582694825
72933138303449
60946016518588
18602770751803
28953229400158
114537104644919
2428148244...

result:

ok 507 numbers

Test #3:

score: 0
Accepted
time: 3ms
memory: 2180kb

input:

983
572982925 807347327 284843142 410633815 303082632 78585340 81366475 726745832 323209673 19883084...

output:

64619788231040
34771316231255
7690174058410
7682293272021
37970268503162
85254621035534
608512714031...

result:

ok 478 numbers

Test #4:

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

input:

960
48149351 792290984 281468426 880845087 404110176 536436217 540144397 586499894 146774112 1667853...

output:

41114344825882
60311968398660
48132881762704
45714920538102
44141876670961
50501010805882
6830661712...

result:

ok 501 numbers

Test #5:

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

input:

988
670799423 629750996 425577355 203572713 505137720 846803449 851438674 446253956 970338552 282223...

output:

46641372787008
27868811408764
117580914181633
4604662320095
78452294512583
29900119929875
2600471168...

result:

ok 489 numbers

Test #6:

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

input:

965
145965849 614694653 422202639 673783985 606165264 157170680 162732950 306008018 646419346 250178...

output:

66113933859392
3885495157880
96944338904036
37862676947951
101176127728590
1653331975884
89002493077...

result:

ok 509 numbers

Subtask #2:

score: 20
Accepted

Test #7:

score: 20
Accepted
time: 169ms
memory: 43460kb

input:

994
621132276 452154665 566311568 143995256 707192808 615021557 621510872 165762080 469983785 365616...

output:

14488483010421
52216943545338
44902719329254
71948990048635
31471596968232
91774250925604
1040746449...

result:

ok 49646 numbers

Test #8:

score: 0
Accepted
time: 163ms
memory: 43136kb

input:

993
96298702 437098322 562936852 614206528 808220352 925388789 932805149 25516142 146064579 33357073...

output:

38789683270103
100927706933150
28255521490049
135070703465875
97933651510985
32282617092619
33488356...

result:

ok 49706 numbers

Test #9:

score: 0
Accepted
time: 156ms
memory: 43480kb

input:

992
718948774 274558334 707045781 84417799 909247896 235756020 244099425 885270205 969629019 4490088...

output:

65926504124246
79783617548920
29410434876213
32226392369641
127025770829730
24560356287715
126516007...

result:

ok 49740 numbers

Test #10:

score: 0
Accepted
time: 153ms
memory: 43284kb

input:

991
194115200 259501991 703671065 407145426 10275439 693606897 702877347 745024267 793193458 4169634...

output:

77752074525804
18031437178974
24962076014026
40877380107636
53160817644438
52125618046811
2776383476...

result:

ok 49613 numbers

Test #11:

score: 0
Accepted
time: 162ms
memory: 43304kb

input:

990
669281627 96962003 847779994 877356698 111302983 3974128 14171623 604778329 469274252 532401579 ...

output:

54458260605737
62909135615977
50571637605894
68862983739597
139380547749282
34772707655098
174397795...

result:

ok 49684 numbers

Subtask #3:

score: 25
Accepted

Test #12:

score: 25
Accepted
time: 871ms
memory: 49920kb

input:

99483
144448053 81905660 844405278 347567969 212330527 314341360 325465900 464532391 292838691 50035...

output:

118744287784850
183508017270541
22139784574143
141473390682466
53977255634599
69641783321153
7120235...

result:

ok 49390 numbers

Test #13:

score: 0
Accepted
time: 871ms
memory: 50132kb

input:

99273
767098125 66849317 988514207 817779241 313358071 772192237 784243822 324286453 116403130 61579...

output:

145833220844811
56006472614354
173564755567788
134897751427864
129013170266099
17564404128072
174735...

result:

ok 49543 numbers

Test #14:

score: 0
Accepted
time: 876ms
memory: 50212kb

input:

99063
242264551 904309330 985139491 140506867 414385615 82559468 95538098 184040515 792483925 583748...

output:

166372909770134
93195362605507
60589093352508
28033336280698
5232209553940
16457726688219
1219092961...

result:

ok 49763 numbers

Test #15:

score: 0
Accepted
time: 875ms
memory: 50472kb

input:

99854
717430978 889252987 129248419 610718139 515413159 392926700 406832375 43794577 616048364 69918...

output:

88247118114710
1375456264603
23618825687309
160426399524338
58385291737771
56691625101160
4516730811...

result:

ok 49923 numbers

Subtask #4:

score: 40
Accepted

Test #16:

score: 40
Accepted
time: 903ms
memory: 50308kb

input:

99644
192597404 726712999 125873703 80929410 616440703 850777577 865610297 51032284 292129158 667141...

output:

480304783882461775
120192859749203484
905523823754698704
16041383460252000
398851626409541632
923674...

result:

ok 49845 numbers

Test #17:

score: 0
Accepted
time: 910ms
memory: 50368kb

input:

99434
815247476 711656656 122498987 551140682 717468247 161144808 176904573 910786347 115693597 7825...

output:

555316709210731726
254633360850421614
1244760050994749402
670079521158507466
309587351225767348
9575...

result:

ok 49699 numbers

Test #18:

score: 0
Accepted
time: 903ms
memory: 50464kb

input:

99224
290413902 549116668 266607916 21351953 818495791 471512040 488198850 770540409 939258037 75053...

output:

970652707558266443
110388969890056720
972694557242680624
260207513526844630
968241720148561517
18853...

result:

ok 49994 numbers

Test #19:

score: 0
Accepted
time: 908ms
memory: 50464kb

input:

99014
765580329 534060325 263233200 344079580 919523335 929362917 946976772 630294471 615338831 8659...

output:

859798349348274160
264084430712406078
889462584998072945
155686554166711840
151314159586743758
88511...

result:

ok 49709 numbers

Test #20:

score: 0
Accepted
time: 884ms
memory: 50548kb

input:

99805
240746755 371520337 407342129 814290852 20550878 239730148 258271048 490048533 438903270 83392...

output:

913556633961091398
862687977070717615
801175214174815058
522770071025650989
271212620675663199
74164...

result:

ok 49829 numbers

Extra Test:

score: 0
Extra Test Passed