QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718266 | #8338. Quad Kingdoms Chess | icpc_zhzx034 | WA | 20ms | 37380kb | C++14 | 2.8kb | 2024-11-06 20:07:46 | 2024-11-06 20:07:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pr;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
// #define mid ((l+r)>>1)
#define popcnt __builtin_popcountll
inline ll read(){
ll x=0, f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = (ll)1e18 + 3, base = 8181891891890168ll;
ll pw[100005];
void init(){
pw[0]=1;
for(ll i=1;i<=100000;i++) pw[i]=((__int128)pw[i-1])*base%mod;
}
struct Hash{
ll sz, hsh;
Hash(ll x=0){ sz=(x>0); hsh=x; }
Hash(ll x,ll y){ sz=x, hsh=y; }
};
inline Hash operator+ (Hash A, Hash B){
return Hash(A.sz+B.sz, (((__int128)A.hsh)*pw[B.sz]+B.hsh)%mod);
}
struct Data{
ll n, a[100005];
Hash tr[400005], rc[400005]; ll mx[400005];
bool lf[400005];
Hash merge(ll pos1, ll pos2){
Hash ret;
if(lf[pos2]) {
if(mx[pos2] >= mx[pos1]) ret = Hash(mx[pos2]);
}else{
if(mx[pos1] > mx[pos2]) ret = merge(pos1, pos2<<1|1);
else ret = merge(pos1, pos2<<1)+rc[pos2];
}
return ret;
}
void pushup(ll pos){
mx[pos] = max(mx[pos<<1], mx[pos<<1|1]);
tr[pos] = tr[pos<<1] + (rc[pos] = merge(pos<<1, pos<<1|1));
}
void build(ll l,ll r,ll pos){
if(l==r) {
lf[pos]=1; tr[pos]=Hash(a[l]);
mx[pos]=a[l]; return;
}
ll mid=(l+r)>>1;
if(l<=mid) build(l,mid,pos<<1);
if(mid<r) build(mid+1,r,pos<<1|1);
pushup(pos);
}
void update(ll l,ll r,ll x,ll v,ll pos){
if(l==r){
tr[pos]=Hash(v);
a[x]=v;
mx[pos]=v; return;
}
ll mid=(l+r)>>1;
if(x<=mid) update(l,mid,x,v,pos<<1);
else update(mid+1,r,x,v,pos<<1|1);
pushup(pos);
}
void init(){
n=read();
for(ll i=n;i>=1;i--) a[i]=read();
build(1, n, 1);
}
void modify(ll x,ll v){
update(1, n, n-x+1, v, 1);
}
}d[2];
void procedure(){
d[0].init(); d[1].init();
ll q=read();
vector<bool>ans;
for(ll i=1;i<=q;i++){
ll o=read()-1, x=read(), y=read();
d[o].modify(x, y);
if(i == 522 && d[0].n==8 && d[1].n==3){
for(ll j=1;j<=d[0].n;j++) cout<<d[0].a[j]<<" "; cout<<endl;
for(ll j=1;j<=d[1].n;j++) cout<<d[1].a[j]<<" "; cout<<endl;
cout<<d[0].tr[1].sz<<" "<<d[1].tr[1].sz<<endl;
cout<<d[0].tr[2].sz<<endl;
cout<<d[0].rc[2].sz<<endl;
cout<<d[0].tr[1].hsh<<" "<<d[1].tr[1].hsh<<endl;
}
ans.pb(d[0].tr[1].hsh == d[1].tr[1].hsh);
}
for(auto x: ans) {
if(x) puts("YES"); else puts("NO");
}
}
int main(){
#ifdef LOCAL
assert(freopen("input.txt","r",stdin));
assert(freopen("output.txt","w",stdout));
#endif
ll T=1;
init();
while(T--) procedure();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 35276kb
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: 20ms
memory: 35172kb
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: 15ms
memory: 35168kb
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: 16ms
memory: 35420kb
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: 15ms
memory: 35212kb
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: 17ms
memory: 37380kb
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: 0
Accepted
time: 16ms
memory: 32096kb
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 YES NO NO NO NO NO NO NO NO NO NO NO NO NO...
result:
ok 200000 tokens
Test #8:
score: 0
Accepted
time: 16ms
memory: 33360kb
input:
1 3 7 4 4 5 5 5 5 4 200000 2 2 4 2 6 4 1 1 4 2 6 4 2 1 3 2 2 3 2 1 3 1 1 5 1 1 5 2 3 5 1 1 4 1 1 4 2 6 5 2 5 1 2 1 2 2 7 2 1 1 5 2 4 5 1 1 2 1 1 3 2 4 2 2 1 3 1 1 3 2 1 1 1 1 1 2 3 1 1 1 4 1 1 5 1 1 1 2 5 2 2 7 3 1 1 5 2 6 4 1 1 4 2 7 4 2 3 3 2 3 1 1 1 3 1 1 3 2 4 4 1 1 4 1 1 2 1 1 1 2 3 1 2 1 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:
ok 200000 tokens
Test #9:
score: -100
Wrong Answer
time: 19ms
memory: 32092kb
input:
8 3 1 2 2 1 4 4 4 3 1 4 4 200000 1 2 1 1 5 1 2 1 1 2 1 1 2 2 2 2 3 1 1 5 5 1 6 2 1 2 5 1 3 1 1 5 1 2 1 5 2 1 2 1 4 4 2 3 3 1 4 3 2 2 2 2 3 1 1 6 4 1 1 3 1 2 3 2 2 5 2 3 3 2 1 3 2 3 4 2 1 4 2 2 5 2 2 4 2 2 2 1 3 1 1 8 2 2 2 3 1 2 2 1 1 2 1 1 1 1 3 1 2 1 3 2 2 3 1 6 2 2 2 4 1 6 3 2 1 1 1 1 4 2 1 4 2 1...
output:
2 5 1 4 1 2 3 5 2 5 5 4 3 2 0 557968113521435645 185634694880003825 NO NO NO 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 N...
result:
wrong answer 1st words differ - expected: 'NO', found: '2'