QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#882480#5098. 第一代图灵机_FJqwq0 1518ms201652kbC++233.9kb2025-02-05 07:37:172025-02-05 07:37:18

Judging History

This is the latest submission verdict.

  • [2025-02-05 07:37:18]
  • Judged
  • Verdict: 0
  • Time: 1518ms
  • Memory: 201652kb
  • [2025-02-05 07:37:17]
  • 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) printf("A"),ans=max(ans,ask1(1,1,n,ql[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(){
	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;
}



/*
3 3 3
20 4 6
1 1 2

*/

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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:

A118571
A90725
A79596
A95154
A95154
A94493
A72411
A100567
A100567
A100567
A100567
A90725
A100567
A100567
A90725
A118571
A94493
A95154
A58191
A118571
A100567
A100567
A100567
A41164
A89208
A118571
A99923
A100567
A100567
A95724
A87252
A100567
A118571
A100567
A100567
A100567
A100567
A100567
A100567
A266...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 1518ms
memory: 201652kb

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:

A8768956
A7653793
A8768956
A8768956
A8768956
A8768956
A8768956
A8768956
A8768956
A8768956
A4475027
A5910916
A8768956
A8768956
A8768956
A8768956
A8123521
A6395030
A8768956
A8768956
A8768956
A8768956
A7031932
A8123521
A7056942
A7653793
A8768956
A8768956
A7653793
A7031932
A5556103
A8768956
A8768956
A70...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 386ms
memory: 165232kb

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:

A11101846442
A9585000736
A8169313164
A8893203953
A6829042365
A8786518335
A7765432179
A13521565121
A9665838393
A9928717717
A8591068889
A38402892
A10890242325
A11913744924
A6427251546
A706054731
A9018337451
A848392952
A12900125462
A10460306772
A9894675091
A7820536753
A11549888934
A13404390616
A1221832...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%