QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#347991 | #8338. Quad Kingdoms Chess | ucup-team346# | WA | 36ms | 29584kb | C++14 | 2.4kb | 2024-03-09 16:31:43 | 2024-03-09 16:31:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define M 100005
int n1,n2,A[M],B[M],q;
void Rd(int &x){
scanf("%d",&x);
}
using ll = long long;
const int BS = 1e5+43;
const ll P=1e9+21;
using pll = pair<ll,ll>;
ll Pw[M];
void Init(){
Pw[0]=1;
for(int i=1;i<M;i++)
Pw[i]=Pw[i-1]*BS%P;
}
struct Seg{
struct TNODE{
int l,r,mx;
pll v;
}tree[M<<2];
#define fa tree[p]
#define lson tree[p<<1]
#define rson tree[p<<1|1]
int pos[M];
pll Ask(pll v,int mx,int p){
ll sz = 0;
ll ret = 0;
while(fa.l^fa.r){
auto [fs,fv] = fa.v;
if(rson.mx >= mx){
ll ls = fs - rson.v.first;
ll lv = (fv + P - 1ll*rson.v.second*Pw[ls]%P)%P;
ret = (ret + 1ll*Pw[sz]*lv)%P;
sz += ls;
p=p<<1|1;
}else p<<=1;
}
if(fa.mx >= mx){
ret = (ret + 1ll*Pw[sz]*fa.mx)%P;
sz++;
// cout<<"OK"<<endl;
}
return pll(sz+v.first,(ret + 1ll*v.second*Pw[sz])%P);
}
void Up(int p){
fa.v = Ask(rson.v,rson.mx,p<<1);
fa.mx = max(lson.mx,rson.mx);
// cout<<fa.v.first<<' '<<fa.v.second<<endl;
// exit(0);
}
void build(int l,int r,int *A,int p=1){
fa.l=l,fa.r=r;
if(l==r){
pos[l]=p,fa.v=pll(1,A[l]),fa.mx=A[l];
return;
}
int mid=l+r>>1;
build(l,mid,A,p<<1);
build(mid+1,r,A,p<<1|1);
Up(p);
// cout<<fa.v.first<<' '<<fa.v.second<<endl;
}
void Update(int x){
int p = pos[x];
fa.v = pll(1,A[x]);
fa.mx = A[x];
for(int i=p>>1;i;i>>=1)Up(i);
}
pll Query(){
return tree[1].v;
}
#undef fa
#undef lson
#undef rson
}T1,T2;
int main(){
Init();
Rd(n1);
for(int i=1;i<=n1;i++)Rd(A[i]);
Rd(n2);
for(int i=1;i<=n2;i++)Rd(B[i]);
Rd(q);
T1.build(1,n1,A);
T2.build(1,n2,B);
while(q--){
int op,x,y;
Rd(op),Rd(x),Rd(y);
if(op==1){
A[x]=y;
T1.Update(x);
}else {
B[x]=y;
T2.Update(x);
}
// cout<<T1.Query().first<<' '<<T1.Query().second<<endl;
puts(T1.Query() == T2.Query()?"YES":"NO");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 29584kb
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: 36ms
memory: 29408kb
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 NO NO NO NO NO NO ...
result:
wrong answer 5th words differ - expected: 'YES', found: 'NO'