QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#618476#8338. Quad Kingdoms Chessucup-team963#WA 36ms16256kbC++141.8kb2024-10-06 22:38:432024-10-06 22:38:44

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 22:38:44]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:16256kb
  • [2024-10-06 22:38:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;++i)
#define ll long long
const int N=1e5+11,Blo=1000;
const ll mod=1e17+7;
__int128 base=19491001;
__int128 p[N];
struct block{
	int n;
	int a[N];
	int bel[N];
	int L[N],R[N],st[N],to[N],sz[N];
	ll h[N];
	vector<int>g[N];
	void build(int x){
		int top=0;
		for(int i=R[x];i>=L[x];--i){
			while(top&&a[st[top]]>=a[i]){
				to[st[top]]=i;
				--top;
			}
			st[++top]=i;
		}
		rep(i,1,top)
			to[st[i]]=0;
		
		rep(i,L[x],R[x]){
			if(to[i]==0){
				sz[i]=1;
				to[i]=i;
				h[i]=a[i];
			}
			else{
				sz[i]=sz[to[i]]+1;
				h[i]=(h[to[i]]*base+a[i])%mod;
				to[i]=to[to[i]];
			}
		}
		top=0;
		rep(i,L[x],R[x]){
			while(top&&a[st[top]]>a[i]){
				--top;
			}
			st[++top]=i;
		}
		g[x].clear();
		rep(i,1,top)
			g[x].push_back(st[i]);
		return;
		for(auto y:g[x]){
			printf("%d ",y);
		}
		printf("\n");
	}
	void init(){
		scanf("%d",&n);
		rep(i,1,n)
			scanf("%d",a+i);
		rep(i,1,n){
			bel[i]=(i-1)/Blo+1;
			if(!L[bel[i]])
				L[bel[i]]=i;
			R[bel[i]]=i;
		}
		rep(i,1,bel[n])
			build(i);
	}
	ll qry(){
		int x=n;
		ll ans=0;
		ans=(ans*p[sz[x]]+h[x])%mod;
		x=to[x];
		for(int i=bel[n]-1;i;--i){
			int l=0,r=g[i].size()-1,ans=-1;
			while(l<=r){
				int mid=(l+r)>>1;
				if(a[g[i][mid]]<=a[x])ans=mid,l=mid+1;
				else r=mid-1;
			}
			if(ans==-1)continue;
			x=g[i][ans];
			ans=(ans*p[sz[x]]+h[x])%mod;
			x=to[x];
		}
		return ans;
	}
};
block A,B;
int main(){
	p[0]=1;
	rep(i,1,1e5)
		p[i]=p[i-1]*base%mod;
	A.init();
	B.init();
	int m;
	scanf("%d",&m);
	while(m--){
		int op,x,y;
		scanf("%d%d%d",&op,&x,&y);
		if(op==1){
			A.a[x]=y;
			A.build(A.bel[x]);
		}
		else{
			B.a[x]=y;
			B.build(B.bel[x]);
		}
		if(A.qry()==B.qry())puts("YES");
		else puts("NO");
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 16256kb

input:

5
1 2 3 4 5
5
5 4 3 2 1
8
1 1 5
1 4 2
1 2 4
1 5 1
1 5 5
2 1 4
2 3 5
2 5 5

output:

NO
NO
NO
YES
NO
NO
NO
YES

result:

ok 8 tokens

Test #2:

score: -100
Wrong Answer
time: 36ms
memory: 14540kb

input:

1
2
6
2 1 1 1 1 1
200000
2 6 2
1 1 1
1 1 1
1 1 2
2 1 1
1 1 2
1 1 1
2 4 1
2 1 2
1 1 1
1 1 2
2 5 1
1 1 1
1 1 2
1 1 1
2 6 1
1 1 2
1 1 2
1 1 2
2 3 1
1 1 1
2 1 1
2 6 2
1 1 2
2 4 1
1 1 2
2 6 1
1 1 2
1 1 1
2 5 2
2 6 2
1 1 1
2 4 2
2 5 2
2 6 2
1 1 1
2 5 1
2 6 2
1 1 2
1 1 1
1 1 1
2 4 1
1 1 2
1 1 2
1 1 2
2 3 2...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO...

result:

wrong answer 5th words differ - expected: 'YES', found: 'NO'