QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#882277#5098. 第一代图灵机_FJqwq0 1173ms208456kbC++233.7kb2025-02-04 23:04:132025-02-04 23:04:13

Judging History

This is the latest submission verdict.

  • [2025-02-04 23:04:13]
  • Judged
  • Verdict: 0
  • Time: 1173ms
  • Memory: 208456kb
  • [2025-02-04 23:04:13]
  • Submitted

answer

//  by wkc

#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*4],tot,id[N];set<int>s[N];
void ins1(int x,int y,int z){
	auto i=s[x].find(y);auto j=i,p=i;
	j++;if(j!=s[x].end()){++tot;id[*j]=tot;tim[tot]=z;}
	if(i!=s[x].begin()){p--;++tot;id[*i]=tot;tim[tot]=z;}
}
void del1(int x,int y,int z){
	auto i=s[x].find(y);auto j=i,p=i;
	j++;if(j!=s[x].end()){change(1,1,q,tim[id[*j]],z,(*i),(*j));}
	if(i!=s[x].begin()){p--;change(1,1,q,tim[id[*i]],z,(*p),(*i));}
}
struct node{int tag,pre;ll ans2;}tree[N*4];
void build1(int k,int l,int r){
	tree[k].pre=1,tree[k].ans2=-inf;
	if(l==r){maxx[k]=sum[l];return ;}
	int mid=l+r>>1;
	build1(ls),build1(rs);
	maxx[k]=max(maxx[lc],maxx[rc]);
}
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{k,tree[k]};
	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[k].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,n,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],pos)-sum[ql[l]-1]);
//			printf("::%d %d %d %d\n",pos,ql[l],ask1(1,1,n,ql[l],pos),sum[ql[l]-1]);
			if(pos+1<=qr[l]) ans=max(ans,ask2(1,1,n,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(){
	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++) s[col[i]].insert(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);
			s[col[x]].erase(x);
			col[x]=y;
			s[col[x]].insert(x);
			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;
}








Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 15ms
memory: 35484kb

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:

3735625
4936863
760056
4520505
4520505
3112480
2457337
4936863
4577550
4577550
6124109
9714640
6356459
9235284
9207116
2334869
3420201
1931872
4480713
4244292
5049080
6196688
6147224
4873773
1865324
7258345
1534298
2670456
2114927
1361937
1589678
2121187
3117761
3117761
3031284
2114927
3117761
27435...

result:

wrong answer 1st lines differ - expected: '118571', found: '3735625'

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 1173ms
memory: 208456kb

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:

3013089490
2383849311
3013089490
3013089490
3302908158
4849680906
4883029600
3013089490
3013089490
4143581152
675252789
2383849311
3013089490
4178645734
3013089490
3013089490
4883029600
3313107301
3013089490
3013089490
4657789943
2383849311
2345197614
4004571217
3013089490
2383849311
3461793652
2383...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 349ms
memory: 170332kb

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:

46702944
46702944
38383720
46702944
38615532
46702944
39035571
46702944
46702944
46702944
34034260
42801975
46702944
46702944
42801975
42801975
46702944
42801975
46702944
46702944
46702944
41821993
46702944
34075405
46702944
46702944
46702944
42801975
46702944
42801975
42801975
42801975
46702944
467...

result:

wrong answer 4th lines differ - expected: '38615532', found: '46702944'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%