QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718224 | #8338. Quad Kingdoms Chess | icpc_zhzx034 | WA | 12ms | 35212kb | C++14 | 2.5kb | 2024-11-06 20:00:41 | 2024-11-06 20:00:41 |
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);
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();
for(ll i=1;i<=q;i++){
ll o=read()-1, x=read(), y=read();
d[o].modify(x, y);
if(i == 522){
cout<<d[0].tr[1].sz<<" "<<d[1].tr[1].sz<<" ";
cout<<d[0].tr[1].hsh<<" "<<d[1].tr[1].hsh<<endl;
}
puts(d[0].tr[1].hsh == d[1].tr[1].hsh ? "YES": "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: 0ms
memory: 35116kb
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: 12ms
memory: 35212kb
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:
wrong answer 522nd words differ - expected: 'NO', found: '1'