QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#545077 | #8338. Quad Kingdoms Chess | pengpeng_fudan# | WA | 28ms | 7492kb | C++23 | 3.1kb | 2024-09-02 22:34:57 | 2024-09-02 22:34:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ll=long long;
ll pw1[100010];ll pw2[100010];
const ll q1=1331;const ll q2=13331;const ll M1=1000000007;const ll M2=998244353;
struct ash{
ll hsh1;ll hsh2;int num;
ash operator*(int x){
return {hsh1*pw1[x]%M1,hsh2*pw2[x]%M2,num};
}
ash operator+(ash a){
return {(hsh1+(a*num).hsh1)%M1,(hsh2+(a*num).hsh2)%M2,num+a.num};
}
ash operator-(ash a){
return {((hsh1-(a*(num-a.num)).hsh1)%M1+M1)%M1,((hsh2-(a*(num-a.num)).hsh2)%M2+M2)%M2,num-a.num};
}
void intt(int x){
hsh1=hsh2=x,num=1;
}
bool operator == (ash x)const {
return hsh1==x.hsh1&&hsh2==x.hsh2&&num==x.num;
}
};
ash ept(){
return {0,0,0};
}
struct seg{
struct node{
ash h;int mx;
}tr[400010];
int n;
void intt(int sz,vector<int>& t){
n=sz;
build(1,1,n,t);
}
void pushup1(int p){
tr[p].mx=max(tr[p<<1].mx,tr[p<<1|1].mx);
}
ash pushup2(int p,int l,int r,int len){
if(l==r){
if(tr[p].mx<=len) return ept();
else return tr[p].h;
}
int mid=(l+r)>>1;
if(tr[p<<1|1].mx>len){
return tr[p].h-tr[p<<1|1].h+pushup2(p<<1|1,mid+1,r,len);
}
else return pushup2(p<<1,l,mid,len);
}
ash get(int p,int l,int r){
int mid=(l+r)>>1;
return ((tr[p<<1].mx<=tr[p<<1|1].mx?ept():pushup2(p<<1,l,mid,tr[p<<1|1].mx)))+tr[p<<1|1].h;
}
void build(int p,int l,int r,vector<int>& t){
if(l==r) {tr[p].h.intt(t[l]);tr[p].mx=t[l];return ;}
int mid=(l+r)>>1;
build(p<<1,l,mid,t);build(p<<1|1,mid+1,r,t);
pushup1(p);
tr[p].h=get(p,l,r);
//cerr<<(ept()+tr[p<<1|1].h).hsh<<' '<<l<<' '<<r<<'\n';
}
void modify(int p,int l,int r,int pz,int num){
if(l==r) {tr[p].h.intt(num);tr[p].mx=num;return ;}
int mid=(l+r)>>1;
if(mid>=pz) modify(p<<1,l,mid,pz,num);
else modify(p<<1|1,mid+1,r,pz,num);
pushup1(p);tr[p].h=get(p,l,r);
}
void modify(int pz,int num){
modify(1,1,n,pz,num);
}
ash query(){
return tr[1].h;
}
};
seg s1,s2;
void solve() {
int n1;
cin>>n1;
vector<int> v1(n1+1);
for(int i=1;i<=n1;i++) cin>>v1[i];
int n2;
cin>>n2;
vector<int> v2(n2+1);
for(int i=1;i<=n2;i++) cin>>v2[i];
s1.intt(n1,v1);
s2.intt(n2,v2);
// cerr<<(s1.query()==s2.query())<<'\n';
int m;
cin>>m;
for(int i=1;i<=m;i++){
int o,x,y;
cin>>o>>x>>y;
if(o==1) s1.modify(x,y);
else s2.modify(x,y);
//cout<<s1.query()<<' '<<s2.query()<<' '<<i<<'\n';
if(s1.query()==s2.query()) cout<<"YES\n";
else cout<<"NO\n";
}
}
int main() {
ios::sync_with_stdio(0),cin.tie(0);
int _ = 1;
pw1[0]=pw2[0]=1;
for(int i=1;i<=100000;i++) pw1[i]=pw1[i-1]*q1%M1;
for(int i=1;i<=100000;i++) pw2[i]=pw2[i-1]*q2%M2;
//cin >> _;
while(_--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 7448kb
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: 28ms
memory: 7492kb
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:
YES NO NO YES YES YES NO NO NO NO YES YES NO YES NO NO NO NO NO NO NO YES NO YES YES YES NO NO YES NO NO NO NO NO NO NO NO NO YES NO NO NO YES YES YES YES YES YES 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...
result:
wrong answer 1st words differ - expected: 'NO', found: 'YES'