QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69495#5098. 第一代图灵机JohnAlfnov0 1449ms206196kbC++203.8kb2022-12-27 21:25:012022-12-27 21:25:02

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-27 21:25:02]
  • Judged
  • Verdict: 0
  • Time: 1449ms
  • Memory: 206196kb
  • [2022-12-27 21:25:01]
  • Submitted

answer

//Code by Lightningfall
//Start coding on ????/??/??
//Finish debugging on ????/??/??
#include<bits/stdc++.h>
using namespace std;
int n,m,q;
int a[200005],c[200005];
int op[200005],o1[200005],o2[200005];
int lst[200005],nxt[200005],pre[200005];
long long s[200005];
int ti[200005];
set<int>se[200005];
int T=0,gg=0;
vector<pair<int,int>>sm[800005];
void add(int l,int r,int o,int ll,int rr,int x,int v){
	if(l>=ll&&r<=rr){
		sm[o].emplace_back(x,v);
		return;
	}
	int mid=(l+r)>>1;
	if(mid>=ll)add(l,mid,o<<1,ll,rr,x,v);
	if(mid<rr)add(mid+1,r,o<<1|1,ll,rr,x,v);
}
void update(int x,int y){
	add(0,gg,1,ti[x],T-1,x,pre[x]);
	ti[x]=T;
}
int mx[800005],lz[800005];
long long xx[800005];
struct apple{
	int o,mx,lz;
	long long xx;
	apple(int o=0,int mx=0,int lz=0,long long xx=0):
		o(o),mx(mx),lz(lz),xx(xx){}
};
stack<apple>st;
void logg(int o){
	st.emplace(apple(o,mx[o],lz[o],xx[o]));
}
void build(int l,int r,int o){
	if(l==r){
		xx[o]=s[l];
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,o<<1);
	build(mid+1,r,o<<1|1);
	xx[o]=max(xx[o<<1],xx[o<<1|1]);
}
void pushdown(int l,int r,int o,int vc){
	if(!lz[o])return;
	int mid=(l+r)>>1;
	if(vc)logg(o<<1),logg(o<<1|1);
	lz[o<<1]=lz[o],lz[o<<1|1]=lz[o];
	mx[o<<1]=lz[o],mx[o<<1|1]=lz[o];
	xx[o<<1]=s[mid]-s[lz[o]-1],xx[o<<1|1]=s[r]-s[lz[o]-1];
	lz[o]=0;
}
void modify(int l,int r,int o,int ll,int rr,int f,int mm){
	if(mm>f)return;
	if(l>=ll&&r<=rr&&max(mm,mx[o])>f)return;
	if(l>=ll&&r<=rr){
		logg(o);
		lz[o]=mx[o]=f;
		xx[o]=s[r]-s[f-1];
		return;
	}
	logg(o);
	pushdown(l,r,o,1);
	int mid=(l+r)>>1;
	int MM=max(mm,mx[o<<1]);
	if(mid>=ll)modify(l,mid,o<<1,ll,rr,f,mm);
	if(mid<rr)modify(mid+1,r,o<<1|1,ll,rr,f,MM);
	mx[o]=max(mx[o<<1],mx[o<<1|1]);
	xx[o]=max(xx[o<<1],xx[o<<1|1]);
}
long long query(int l,int r,int o,int ll,int rr){
	if(l>=ll&&r<=rr)return xx[o];
	int mid=(l+r)>>1;
	pushdown(l,r,o,0);
	long long ans=0;
	if(mid>=ll)ans=max(ans,query(l,mid,o<<1,ll,rr));
	if(mid<rr)ans=max(ans,query(mid+1,r,o<<1|1,ll,rr));
	return ans;
}
vector<int>xw[200005];
int find(int l,int r,int o,int x){
	if(l==r){
		if(mx[o]>x)return l;
		return l+1;
	}
	int mid=(l+r)>>1;
	if(mx[o<<1]>x)return find(l,mid,o<<1,x);
	return find(mid+1,r,o<<1|1,x);
}
void solve(int l,int r,int o){
	while(st.size())st.pop();
	for(auto pi:sm[o]){
		int x=pi.first,y=pi.second;
		modify(1,n,1,x,n,y+1,0);
	}
	stack<apple>stt=st;
	if(l==r){
		for(auto tt:xw[l]){
			int L=o1[tt],R=o2[tt];
			int wz=find(1,n,1,L);
			long long ans=0;
			if(wz-1>=L)ans=max(ans,s[min(R,wz-1)]-s[L-1]);
			if(wz<=R)ans=max(ans,query(1,n,1,wz,R));
			printf("%lld\n",ans);
		}
	}else{
		int mid=(l+r)>>1;
		solve(l,mid,o<<1);
		solve(mid+1,r,o<<1|1);
	}
	while(stt.size()){
		auto at=stt.top();
		stt.pop();
		lz[at.o]=at.lz;
		mx[at.o]=at.mx;
		xx[at.o]=at.xx;
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),s[i]=a[i]+s[i-1];
	for(int i=1;i<=n;++i)scanf("%d",&c[i]);
	for(int i=1;i<=n;++i)nxt[i]=n+1,ti[i]=T;
	for(int i=1;i<=m;++i){
		se[i].emplace(0);
		se[i].emplace(n+1);
	}
	for(int i=1;i<=n;++i){
		pre[i]=lst[c[i]],nxt[lst[c[i]]]=i;
		lst[c[i]]=i;
		se[c[i]].emplace(i);
	}
	for(int i=1;i<=q;++i)
		scanf("%d%d%d",&op[i],&o1[i],&o2[i]),gg+=(op[i]-1);
	for(int i=1;i<=q;++i){
		if(op[i]==2){
			++T;
			int x=o1[i],cc=o2[i];
			if(cc==c[i])continue;
			auto it=se[cc].upper_bound(x);
			int wz=*it;
			--it;
			int zw=*it;
			if(nxt[x]<=n)update(nxt[x],pre[x]);
			pre[nxt[x]]=pre[x],nxt[pre[x]]=nxt[x];
			update(x,zw);
			pre[x]=zw,nxt[zw]=x;
			if(wz<=n)update(wz,x);
			pre[wz]=x,nxt[x]=wz;
			se[c[x]].erase(x);
			c[x]=cc;
			se[c[x]].emplace(x);
		}else{
			xw[T].emplace_back(i);
		}
	}
	for(int i=1;i<=n;++i)add(0,gg,1,ti[i],gg,i,pre[i]);
	solve(0,gg,1);
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 19ms
memory: 38640kb

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
144241
93903
109391
109391
94493
110341
144241
144796
144796
109391
144241
144241
144241
128064
152550
94493
95154
85415
127909
144796
109391
144241
39374
113232
144241
124717
144241
144241
95724
101816
144241
152550
144241
144241
144241
144796
144241
144241
29296
144241
144796
144796
152550
...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 1449ms
memory: 206196kb

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:

2981078
2199309
2496610
2496610
2981078
2981078
2981078
2981078
2496610
2981078
1847081
1790050
2981078
2981078
2981078
2981078
2802028
1929645
2981078
2981078
2981078
2981078
2251375
2802028
2173891
2199309
2981078
2981078
2318510
2251375
1903483
2981078
2981078
2318510
2981078
2981078
2318510
1790...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 299ms
memory: 109928kb

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
38615532
38615532
42801975
39035571
46702944
46702944
46702944
27438528
38402892
46702944
46702944
42801975
42323113
39035571
42323113
46702944
46702944
46702944
41821993
46702944
34075405
46702944
38615532
46702944
28680653
46702944
42801975
42801975
38025842
46702944
467...

result:

wrong answer 2064th lines differ - expected: '19955796', found: '20257038'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%