QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883008#5098. 第一代图灵机_FJqwq30 1522ms202472kbC++233.9kb2025-02-05 14:21:532025-02-05 14:21:53

Judging History

This is the latest submission verdict.

  • [2025-02-05 14:21:53]
  • Judged
  • Verdict: 30
  • Time: 1522ms
  • Memory: 202472kb
  • [2025-02-05 14:21:53]
  • Submitted

answer

#pragma target("avx512f,sse2,sse3,sse4,sse4.2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=250005,M=5000005,inf=1e18;
int n,m,q,a[N],col[N],ql[N],qr[N];
ll sum[N],maxx[N*4];
#define lc k<<1
#define rc k<<1|1
#define ls lc,l,mid
#define rs rc,mid+1,r
struct T{int x,y;};vector<T>v[N*4];
void change(int k,int l,int r,int x,int y,int v1,int v2){
	if(x<=l&&r<=y){
		v[k].push_back(T{v1+1,v2});
		return ;
	}
	int mid=l+r>>1;
	if(x<=mid) change(ls,x,y,v1,v2);
	if(mid<y) change(rs,x,y,v1,v2);
}
int tim[N],tot;set<int>s[N];
void ins1(int x,int y,int z){
	s[x].insert(y);
	auto i=s[x].find(y);auto j=i,p=i;
	j++;if(i!=s[x].begin())p--;
	if(i!=s[x].begin())if(j!=s[x].end()){change(1,1,q,tim[*j],z,(*p),(*j));}
	if(j!=s[x].end()) tim[*j]=z;
	if(i!=s[x].begin()) tim[*i]=z;
}
void del1(int x,int y,int z){
	auto i=s[x].find(y);auto j=i,p=i;
	j++;if(i!=s[x].begin())p--;
	if(j!=s[x].end()){change(1,1,q,tim[*j],z,(*i),(*j));}
	if(i!=s[x].begin()){change(1,1,q,tim[*i],z,(*p),(*i));}
	if(i!=s[x].begin())if(j!=s[x].end()) tim[*j]=z;
	s[x].erase(y);
}
struct node{int tag,pre;ll ans2;}tree[N*4];
void build1(int k,int l,int r){
	tree[k].pre=1;
	if(l==r){tree[k].ans2=maxx[k]=sum[l];return ;}
	int mid=l+r>>1;
	build1(ls),build1(rs);
	maxx[k]=max(maxx[lc],maxx[rc]);
	tree[k].ans2=max(tree[lc].ans2,tree[rc].ans2);
}
ll ask1(int k,int l,int r,int x,int y){
	if(x<=l&&r<=y) return maxx[k];
	int mid=l+r>>1;
	if(x<=mid&&mid<y) return max(ask1(ls,x,y),ask1(rs,x,y));
	if(x<=mid) return ask1(ls,x,y);
	return ask1(rs,x,y);
}
int top;struct A{int p;node w;}stk[M];
void pushdown(int k){
	stk[++top]=A{lc,tree[lc]};
	stk[++top]=A{rc,tree[rc]};
	if(tree[k].tag){
		tree[lc].pre=tree[rc].pre=tree[k].tag;
		tree[lc].tag=tree[rc].tag=tree[k].tag;
		tree[lc].ans2=maxx[lc]-sum[tree[k].tag-1];
		tree[rc].ans2=maxx[rc]-sum[tree[k].tag-1];
		tree[k].tag=0;
	}
}
void pushup(int k){
	tree[k].pre=max(tree[lc].pre,tree[rc].pre);
	tree[k].ans2=max(tree[lc].ans2,tree[rc].ans2);}
int ask(int k,int l,int r,int d){
	stk[++top]=A{k,tree[k]};
	if(l==r) return l+(tree[k].pre<=d);
	int mid=l+r>>1;
	pushdown(k);
	if(tree[lc].pre<=d) return ask(rs,d);
	return ask(ls,d);
}
void change2(int k,int l,int r,int x,int y,int d){
	stk[++top]=A{k,tree[k]};
	if(x<=l&&r<=y){
		tree[k].tag=tree[k].pre=d;
		tree[k].ans2=maxx[k]-sum[d-1];
		return ;
	}
	int mid=l+r>>1;
	pushdown(k);
	if(x<=mid) change2(ls,x,y,d);
	if(mid<y) change2(rs,x,y,d);
	pushup(k);
}
ll ask2(int k,int l,int r,int x,int y){
	stk[++top]=A{k,tree[k]};
	if(x<=l&&r<=y) return tree[k].ans2;
	int mid=l+r>>1;
	pushdown(k);
	if(x<=mid&&mid<y) return max(ask2(ls,x,y),ask2(rs,x,y));
	if(x<=mid) return ask2(ls,x,y);
	return ask2(rs,x,y);
}

void work(int k,int l,int r){
	int las=top,p;
//	printf("%d %d %d\n",k,l,r);
	for(T e:v[k]){
//		printf(":::%d %d\n",e.x,e.y);
		p=ask(1,1,n,e.x)-1;
		if(e.y<=p) change2(1,1,n,e.y,p,e.x); 
	}
	if(l==r){
		if(ql[l]!=0){
			int pos;ll ans=0;
			pos=ask(1,1,n,ql[l])-1;
			if(ql[l]<=pos) ans=max(ans,ask1(1,1,n,ql[l],min(qr[l],pos))-sum[ql[l]-1]);
			if(pos+1<=qr[l]) ans=max(ans,ask2(1,1,n,max(ql[l],pos+1),qr[l]));
			printf("%lld\n",ans);
		}
	}
	else{
		int mid=l+r>>1;
		work(ls);
		work(rs);
	}
	while(top>las){
		tree[stk[top].p]=stk[top].w;
		top--;
	}
}
int main(){
//	freopen("data.in","r",stdin);
//	freopen("data.out","w",stdout);
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=n;i++) scanf("%d",&col[i]);
	for(int i=1;i<=n;i++) ins1(col[i],i,1);
	for(int i=1,op,x,y;i<=q;i++){
		scanf("%d%d%d",&op,&x,&y);
		if(op==2){
			del1(col[x],x,i);
			col[x]=y;
			ins1(col[x],x,i);
		}
		else ql[i]=x,qr[i]=y;
	}
	for(int i=1;i<=n;i++) del1(col[i],i,q);
	build1(1,1,n);
	work(1,1,q);
	return 0;
}

/*
3 3 3
10 1 1 
1 3 1 
1 2 2
2 2 1
1 1 3


*/

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 18ms
memory: 34048kb

input:

5000 200 5000
2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...

output:

118571
90725
79596
95154
95154
94493
72411
100567
100567
100567
100567
90725
100567
100567
90725
118571
94493
95154
58191
118571
100567
100567
100567
39374
89208
118571
99923
100567
100567
95724
87252
100567
118571
100567
100567
100567
100567
100567
100567
26617
100567
99923
100567
118571
100567
100...

result:

ok 3799 lines

Test #2:

score: 10
Accepted
time: 14ms
memory: 35964kb

input:

5000 1000 5000
451 521 3465 4281 3422 1186 2547 3341 2060 1467 717 2115 2513 2471 1399 1812 3070 2173 521 1621 2801 4020 4493 138 4162 97 1179 171 4011 3340 2393 689 1830 3981 2352 3352 3561 2969 1037 1205 2390 3916 1578 2313 2433 885 1097 1820 739 4483 3241 3861 1547 665 1449 4133 4877 1005 3510 18...

output:

188595
209663
209663
209663
209663
209663
209282
209663
209663
176195
156041
141623
176195
209663
209663
209282
175706
209663
209663
209663
209663
209663
209282
209663
209663
209663
188595
209282
209663
183686
209663
163197
209663
183686
209663
183686
209663
175706
209663
209663
209663
209663
209663...

result:

ok 3724 lines

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 1522ms
memory: 201500kb

input:

200000 10 200000
55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...

output:

8768956
7653793
8768956
8768956
8768956
8768956
8768956
8768956
8768956
8768956
4475027
5910916
8768956
8768956
8768956
8768956
8123521
6395030
8768956
8768956
8768956
8768956
7031932
8123521
7056942
7653793
8768956
8768956
7653793
7031932
5556103
8768956
8768956
7031932
8768956
8768956
7653793
5407...

result:

wrong answer 1st lines differ - expected: '1232419', found: '8768956'

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 393ms
memory: 164684kb

input:

200000 20000 200000
30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...

output:

6621858508
9585000736
931223557
2620475833
750333254
8786518335
3005023565
9839704978
9665838393
2836756946
125441385
38402892
3319086817
11913744924
6427251546
706054731
4220592768
848392952
12900125462
4642753825
9894675091
5386259737
3380344537
1694960013
11951325862
2557945957
10039460521
286806...

result:

wrong answer 1st lines differ - expected: '46702944', found: '6621858508'

Subtask #4:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #9:

score: 20
Accepted
time: 213ms
memory: 124268kb

input:

50000 1000 50000
22098 40691 15626 6766 15467 15377 43375 7991 25841 6053 2031 38833 19761 42385 9421 28399 42001 15985 31206 30047 14001 7441 8377 5217 4402 37695 41393 25926 38137 32913 23203 31265 31401 32772 32905 24167 5233 24058 41685 26999 41 18461 15721 49365 49676 3151 29237 22894 37323 272...

output:

2734990
2469610
2734990
2734990
2734990
1967019
2734990
2469610
2469610
2388133
1799671
2469610
2734990
2734990
2734990
1957691
2273183
1952934
2734990
2168141
2273183
2436566
2734990
2469610
2469610
2273183
1986640
2734990
2152587
2152587
2436566
1957691
2734990
1952934
2469610
1927323
2734990
2734...

result:

ok 37426 lines

Test #10:

score: 20
Accepted
time: 206ms
memory: 127592kb

input:

50000 3000 50000
26345 22237 37825 18017 10571 36611 13641 34871 23281 33887 40852 37033 41999 7157 733 14250 26317 9438 4580 4336 15601 29921 20225 2668 14241 17493 20241 46199 1 12641 21281 45365 16691 27521 2163 11473 22971 2119 29681 21301 37841 34390 27153 27251 31049 25913 15678 36231 35301 22...

output:

2745361
3808608
3808608
4264616
4235767
4264616
3174029
4264616
3808608
4264616
3547291
4264616
3808608
3753676
4264616
4264616
3808608
4235767
3753676
4264616
3808608
4264616
3808608
3753676
3753676
4235767
4264616
4264616
3808608
4264616
4264616
2858660
4264616
4264616
3753676
4264616
4264616
3808...

result:

ok 37630 lines

Test #11:

score: 20
Accepted
time: 202ms
memory: 118500kb

input:

50000 5000 50000
31653 19639 4311 25169 31659 42766 11977 27731 23651 14701 8483 16344 2247 40647 9039 16489 35801 4082 38419 45856 17665 38754 43083 40671 32408 48467 27185 3144 31701 33733 6716 14133 2105 40551 3921 38809 24595 4295 30349 25016 16450 20081 39305 27803 15270 11705 17361 19567 29924...

output:

5126664
5142382
5142382
5142382
5142382
5142382
5142382
5142382
5142382
5126664
5410245
4278120
5142382
4278120
5772763
5410245
5126664
5410245
4745095
4525361
4525361
5410245
5410245
4525361
4420696
5410245
5142382
4745095
5772763
5410245
4238451
5410245
5410245
5410245
5410245
5410245
5410245
4745...

result:

ok 37522 lines

Test #12:

score: 20
Accepted
time: 88ms
memory: 93012kb

input:

50000 25000 50000
34538 6631 20121 905 26818 44368 30670 37731 40463 15201 39981 24285 41901 47121 5301 44467 49610 40975 31931 23680 2231 41395 15878 24760 30222 49987 22961 6951 33701 23633 9095 13546 7964 16011 38636 14817 13011 37269 27797 11376 7936 31649 40488 37836 11065 7891 39391 21437 4694...

output:

266141794
618840980
145032186
57978911
409865397
29353526
24595926
275518913
613677417
455611683
624185824
384230855
137601929
58120402
80585932
246836251
626286654
161877183
385544628
401507685
86584674
54668579
626286654
379213776
343390891
455517388
324928870
566756301
622591682
117295749
3414503...

result:

ok 25000 lines

Subtask #5:

score: 0
Wrong Answer

Dependency #4:

100%
Accepted

Test #13:

score: 0
Wrong Answer
time: 1273ms
memory: 202472kb

input:

200000 1000 200000
86881 181241 36705 81141 134314 91161 170817 78506 98711 53236 135870 199649 121729 158986 42323 190297 144513 19767 104041 191515 30393 161425 177941 126191 43710 96703 113443 180950 172245 27687 83019 80185 56193 99571 141101 110667 133377 168529 16422 65729 99846 187702 68903 6...

output:

30998244
25600266
30998244
28101981
25760491
28101981
21142036
30998244
26438050
28101981
30998244
26438050
27727544
30998244
28101981
30998244
27727544
30998244
25271237
25852161
30998244
27066121
14488095
25384668
27727544
30998244
26245772
30998244
30998244
30998244
30998244
30998244
26438050
256...

result:

wrong answer 1st lines differ - expected: '10804871', found: '30998244'