QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#591333 | #8338. Quad Kingdoms Chess | Rosmontispes | WA | 31ms | 4628kb | C++20 | 3.2kb | 2024-09-26 15:27:04 | 2024-09-26 15:27:04 |
Judging History
answer
//14:23
#include<bits/stdc++.h>
using namespace std;
const int N = 100000 + 200;
const long long mod = 998244353;
const long long A = 13331;
long long pre[N];
struct segtree{
#define ls(x) tree[x].ls
#define rs(x) tree[x].rs
struct node{
int mxlen,maxn,ls,rs;
long long hash;
};
int n,tot,rt;
vector<int>ar;
vector<node>tree;
segtree(int _n,vector<int>tmp):rt(0),tot(0),ar(tmp),n(_n),tree(4 * _n + 200){
build(1,n,rt);
}
pair<int,long long> qur(int x,int mx){
if(!x)
return {0,0};
if(!tree[x].ls && !tree[x].rs)
return {tree[x].mxlen,tree[x].hash};
if(tree[x].maxn < mx)
return {0,0};
if(tree[ls(x)].maxn < mx)
return qur(rs(x),mx);
if(tree[rs(x)].maxn >= mx){
pair<int,long long>ret = {tree[x].mxlen,tree[x].hash};
auto rret = qur(rs(x),mx);
ret.first = ret.first - tree[rs(x)].mxlen + rret.first;
ret.second = (ret.second - tree[rs(x)].hash + rret.second + mod) % mod;
return ret;
} else {
return qur(ls(x),mx);
}
}
node merge(int x){
node tmp = tree[x];
if(tree[rs(x)].maxn > tree[ls(x)].maxn){
tmp.mxlen = tree[rs(x)].mxlen;
tmp.maxn = tree[rs(x)].maxn;
tmp.hash = tree[rs(x)].hash;
return tmp;
} else {
auto [len,lhash] = qur(ls(x),tree[rs(x)].maxn);
tmp.mxlen = tree[rs(x)].mxlen + len;
tmp.maxn = tree[ls(x)].maxn;
tmp.hash = (lhash * pre[tree[rs(x)].mxlen] % mod + tree[rs(x)].hash) % mod;
return tmp;
}
}
void build(int l,int r,int &x){
if(!x)
x = ++ tot;
if(l == r){
tree[x] = {1,ar[l],0,0,ar[l]};
return;
}
int mid = (l + r) / 2;
build(l,mid,ls(x)),build(mid + 1,r,rs(x));
tree[x] = merge(x);
}
void modify(int l,int r,int x,int k,int val){
if(l == r){
tree[x].maxn = tree[x].hash = val;
return;
}
int mid = (l + r) / 2;
if(k <= mid)
modify(l,mid,ls(x),k,val);
else
modify(mid + 1,r,rs(x),k,val);
tree[x] = merge(x);
}
};
void solve(){
int n,m;
cin>>n;
vector<int>p(n + 1);
for(int i = 1;i <= n;i ++)
cin>>p[i];
cin>>m;
vector<int>q(m + 1);
for(int i = 1;i <= m;i ++){
cin>>q[i];
}
segtree A(n,p),B(m,q);
int Q;
cin>>Q;
for(int i = 1;i <= Q;i ++){
int opr,k,val;
cin>>opr>>k>>val;
if(opr == 1)
A.modify(1,n,1,k,val);
else
B.modify(1,m,1,k,val);
if(A.tree[A.rt].hash == B.tree[B.rt].hash && A.tree[A.rt].mxlen == B.tree[B.rt].mxlen)
cout<<"YES\n";
else
cout<<"NO\n";
}
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
pre[0] = 1;
for(int i = 1;i <= 100000;i ++){
pre[i] = pre[i - 1] * A % mod;
}
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4628kb
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: 23ms
memory: 4432kb
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: 4368kb
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: 0
Accepted
time: 31ms
memory: 4600kb
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:
ok 200000 tokens
Test #5:
score: 0
Accepted
time: 24ms
memory: 4372kb
input:
4 1 1 2 2 1 1 200000 2 1 2 1 1 3 1 2 1 2 1 2 2 1 2 2 1 3 2 1 1 2 1 1 1 4 2 2 1 3 1 3 1 1 2 1 1 3 2 2 1 1 1 4 2 2 1 1 2 1 2 1 1 1 2 1 2 2 1 1 1 4 1 1 2 2 2 1 1 1 1 1 1 4 3 2 1 3 1 1 3 2 1 2 1 2 1 2 1 1 2 1 1 2 1 1 2 1 3 2 1 2 1 2 3 2 1 3 1 3 3 2 1 1 1 2 3 2 1 2 1 1 2 2 1 2 2 1 3 1 2 1 1 4 3 2 1 2 2 1...
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 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 YES NO NO NO NO YES NO NO NO NO YES YES NO NO NO NO NO NO NO NO NO N...
result:
ok 200000 tokens
Test #6:
score: 0
Accepted
time: 23ms
memory: 4376kb
input:
2 4 2 4 2 3 3 2 200000 1 1 2 1 2 2 1 2 2 1 2 4 1 1 2 1 2 4 2 2 1 1 1 3 2 3 2 2 3 1 2 2 4 2 3 2 2 2 1 1 1 4 1 2 4 2 2 1 1 1 2 2 1 2 2 4 4 1 2 4 1 2 3 2 4 4 2 3 1 2 1 3 2 3 1 2 2 1 1 1 2 2 2 1 1 2 3 1 2 2 1 2 1 1 2 4 1 2 4 1 1 3 1 1 4 2 1 3 1 1 1 1 2 4 2 1 2 2 3 4 1 2 4 2 2 1 1 2 1 2 3 2 1 2 3 2 3 3 1...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES YES NO NO NO NO NO NO NO NO NO NO NO YES YES YES 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 NO NO NO NO NO NO N...
result:
ok 200000 tokens
Test #7:
score: -100
Wrong Answer
time: 30ms
memory: 4408kb
input:
7 3 3 4 1 1 3 3 5 3 3 2 1 4 200000 2 2 1 2 2 1 2 5 1 1 6 1 1 5 2 2 1 4 1 4 2 1 6 4 1 7 1 1 2 3 2 5 1 2 5 4 1 6 2 1 5 2 1 4 1 1 2 1 2 2 2 1 3 4 1 7 2 1 6 3 2 5 1 1 5 1 1 7 3 2 1 3 2 3 1 1 3 2 2 2 2 1 7 4 2 1 4 1 3 2 1 1 2 1 5 3 1 5 3 2 2 2 1 5 3 2 5 3 2 3 2 1 1 3 1 2 2 2 2 1 2 1 4 2 1 2 1 3 4 2 1 1 1...
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:
wrong answer 87th words differ - expected: 'YES', found: 'NO'