QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#618459 | #8338. Quad Kingdoms Chess | ucup-team963# | WA | 33ms | 15316kb | C++14 | 1.8kb | 2024-10-06 22:28:19 | 2024-10-06 22:28:20 |
Judging History
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;
for(int i=R[x];i>=L[x];--i){
while(top&&a[st[top]]<a[i]){
to[st[top]]=i;
--top;
}
st[++top]=i;
}
g[x].clear();
rep(i,1,top)
g[x].push_back(st[i]);
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 14476kb
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: 33ms
memory: 15316kb
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'