QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#882284#5098. 第一代图灵机_FJqwq0 835ms208412kbC++233.8kb2025-02-04 23:11:092025-02-04 23:11:10

Judging History

This is the latest submission verdict.

  • [2025-02-04 23:11:10]
  • Judged
  • Verdict: 0
  • Time: 835ms
  • Memory: 208412kb
  • [2025-02-04 23:11:09]
  • 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{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[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,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],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;
}



/*
3 3 3
20 4 6
1 1 2

*/

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 11ms
memory: 39940kb

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:

152550
144796
101276
144241
144241
144241
144796
144241
144796
144796
144241
144796
144241
144241
128064
152550
144241
144241
144241
144241
144796
144241
144241
144241
128064
144241
124717
144241
144241
101276
128064
144241
152550
144796
144796
144241
144796
144241
144796
144241
144796
144796
144796...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 835ms
memory: 208412kb

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:

2597207
2225779
2498759
2498759
2498759
2597207
2498759
2498759
2498759
2597207
2125539
2225779
2597207
2498759
2597207
2498759
2498759
2498759
2498759
2597207
2597207
2498759
2597207
2498759
2498759
2225779
2597207
2498759
2597207
2597207
2225779
2498759
2597207
2597207
2597207
2498759
2597207
2225...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 382ms
memory: 172016kb

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:

7356460895
12769117913
4423927617
5147818406
3083656818
12769117913
4020046632
10000513770
12769117913
6183332170
4845683342
12769117913
7144856778
12769117913
12769117913
12769117913
5272951904
12769117913
12769117913
6714921225
12769117913
11248096897
7804503387
9659005069
12769117913
5102833909
1...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%