QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#668686 | #8338. Quad Kingdoms Chess | kjhhjki_fan# | WA | 27ms | 13916kb | C++20 | 2.1kb | 2024-10-23 15:28:20 | 2024-10-23 15:28:28 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=(k);++i)
#define MAXN 1000005
typedef long long ll;
int n1,n2,m;
const int p1=998244353,p2=1000000007;
ll pw1[MAXN],pw2[MAXN];
struct sgt{
int seq[MAXN];
struct data{
int sz;
ll v1,v2;
inline void set(int x){
sz=1,v1=v2=x;
}
inline bool operator == (const data &rhs)const{
return sz==rhs.sz&&v1==rhs.v1&&v2==rhs.v2;
}
inline data operator + (const data &rhs)const{
if(!sz) return rhs;
if(!rhs.sz) return *this;
return (data){
sz+rhs.sz,
(v1*pw1[rhs.sz]+rhs.v1)%p1,
(v2*pw2[rhs.sz]+rhs.v2)%p2
};
}
};
struct node{
node *ls,*rs;
int mx;
data hash;
}pool[MAXN<<1],*pos=pool,*root;
#define mid (l+r>>1)
#define lson tree->ls,l,mid
#define rson tree->rs,mid+1,r
inline data calc(node *tree,int l,int r,int val){
if(tree->mx<val) return (data){0,0,0};
if(l==r) return tree->hash;
if(tree->ls->mx<val) return calc(rson,val);
return tree->ls->hash+calc(rson,tree->ls->mx);
}
inline void pushup(node *tree,int l,int r){
tree->mx=std::max(tree->ls->mx,tree->rs->mx);
tree->hash=tree->ls->hash+calc(rson,tree->ls->mx);
}
inline void build(node *&tree,int l,int r){
tree=++pos;
if(l==r) return tree->mx=seq[l],tree->hash.set(seq[l]);
else build(lson),build(rson),pushup(tree,l,r);
}
inline void update(node *tree,int l,int r,int x,int val){
if(l==r) return tree->mx=val,tree->hash.set(val),void();
if(x<=mid) update(lson,x,val);
else update(rson,x,val);
pushup(tree,l,r);
}
}t1,t2;
int main(){
std::ios::sync_with_stdio(0);
std::cin.tie(0),std::cout.tie(0);
std::cin>>n1;
rep(i,1,n1) std::cin>>t1.seq[n1-i+1];
std::cin>>n2;
rep(i,1,n2) std::cin>>t2.seq[n2-i+1];
pw1[0]=pw2[0]=1;
rep(i,1,std::max(n1,n2)) pw1[i]=pw1[i-1]*100003%p1;
rep(i,1,std::max(n1,n2)) pw2[i]=pw2[i-1]*100003%p2;
t1.build(t1.root,1,n1),t2.build(t2.root,1,n2);
std::cin>>m;
while(m--){
int opt,x,y;
std::cin>>opt>>x>>y;
if(opt==1) t1.update(t1.root,1,n1,n1-x+1,y);
else t2.update(t2.root,1,n2,n2-x+1,y);
std::cout<<(t1.root->hash==t2.root->hash?"YES\n":"NO\n");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 13800kb
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: 0
Accepted
time: 26ms
memory: 13892kb
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 YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES YES YES 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 N...
result:
ok 200000 tokens
Test #3:
score: 0
Accepted
time: 26ms
memory: 13916kb
input:
6 2 1 1 2 1 2 1 1 200000 2 1 1 1 1 2 1 1 1 2 1 2 2 1 1 2 1 1 2 1 2 2 1 2 1 1 2 1 3 1 1 6 2 1 5 2 1 4 2 1 3 1 2 1 2 1 4 2 1 4 2 2 1 2 2 1 2 1 3 1 1 6 1 1 1 2 2 1 1 1 6 1 1 3 1 1 5 2 1 6 2 1 5 2 2 1 2 1 2 1 1 5 2 2 1 1 2 1 1 1 6 1 2 1 2 2 1 1 1 3 2 2 1 1 1 6 1 1 4 2 1 2 1 1 1 1 2 1 1 1 2 1 1 6 2 1 6 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 NO NO NO NO NO NO ...
result:
ok 200000 tokens
Test #4:
score: -100
Wrong Answer
time: 27ms
memory: 13828kb
input:
6 1 3 1 2 1 2 6 2 1 3 3 3 1 200000 2 4 2 1 2 1 1 6 2 2 3 2 1 1 1 1 6 2 1 6 2 1 3 2 2 6 1 2 4 3 1 1 2 2 5 2 2 6 2 2 3 1 1 4 3 1 3 1 2 5 2 2 4 2 2 1 3 1 1 1 2 2 2 2 4 2 1 5 3 1 6 3 2 6 3 1 5 3 2 5 3 2 4 1 2 4 2 1 1 2 1 6 1 2 6 1 1 2 3 1 1 3 1 1 1 2 6 3 2 4 1 1 4 2 2 2 1 1 3 1 1 1 3 1 1 3 1 4 3 1 3 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 YES YES YES YES NO YES 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 N...
result:
wrong answer 123rd words differ - expected: 'YES', found: 'NO'