QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#545056#8338. Quad Kingdoms Chesspengpeng_fudan#WA 25ms7936kbC++232.7kb2024-09-02 22:24:142024-09-02 22:24:14

Judging History

你现在查看的是最新测评结果

  • [2024-09-02 22:24:14]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:7936kb
  • [2024-09-02 22:24:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ll=long long;
ull pw[100010];ull q=1331;
struct ash{
    ull hsh;int num;
    ash operator*(int x){
        return {hsh*pw[x],num};
    }
    ash operator+(ash a){
        return {hsh+(a*num).hsh,num+a.num};
    }
    ash operator-(ash a){
        return {hsh-(a*(num-a.num)).hsh,num-a.num};
    }
    void intt(int x){
        hsh=x,num=1;
    }
};
ash ept(){
    return {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);
    }
    ull query(){
        return tr[1].h.hsh;
    }
};
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;
    pw[0]=1;
    for(int i=1;i<=100000;i++)  pw[i]=pw[i-1]*q;
    //cin >> _;
    while(_--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7936kb

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: 25ms
memory: 6392kb

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'