QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591312#8338. Quad Kingdoms ChessRosmontispesWA 23ms4400kbC++203.1kb2024-09-26 15:20:412024-09-26 15:20:41

Judging History

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

  • [2024-09-26 15:20:41]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:4400kb
  • [2024-09-26 15:20:41]
  • 提交

answer

//14:23
#include<bits/stdc++.h>
using namespace std;
const int N = 100000 + 200;
const long long mod = 998244353;
const long long A = 13331;
long long pre[N];
struct segtree{
    #define ls(x) tree[x].ls
    #define rs(x) tree[x].rs
    struct node{
        int mxlen,maxn,ls,rs;
        long long hash;
    };
    int n,tot,rt;
    vector<int>ar;
    vector<node>tree;
    segtree(int _n,vector<int>tmp):rt(0),tot(0),ar(tmp),n(_n),tree(4 * _n + 200){
        build(1,n,rt);
    }
    pair<int,long long> qur(int x,int mx){
        if(!x)
            return {0,0};
        if(tree[x].maxn < mx)
            return {0,0};
        if(tree[ls(x)].maxn < mx)
            return qur(rs(x),mx);
        if(tree[rs(x)].maxn >= mx){
            pair<int,long long>ret = {tree[x].mxlen,tree[x].hash};
            auto rret = qur(rs(x),mx);
            ret.first = ret.first - tree[rs(x)].mxlen + rret.first;
            ret.second = (ret.second - tree[rs(x)].hash + rret.second + mod) % mod;
            return ret;
        } else {
            return qur(ls(x),mx);
        }
    }  
    node merge(int x){
        node tmp = tree[x];
        if(tree[rs(x)].maxn > tree[ls(x)].maxn){
            tmp.mxlen = tree[rs(x)].mxlen;
            tmp.maxn = tree[rs(x)].maxn;
            tmp.hash = tree[rs(x)].hash;
            return tmp;
        } else {
            auto [len,lhash] = qur(ls(x),tree[rs(x)].maxn);
            tmp.mxlen = tree[rs(x)].mxlen + len;
            tmp.maxn = tree[ls(x)].maxn;
            tmp.hash = (lhash * pre[tree[rs(x)].mxlen] % mod + tree[rs(x)].hash) % mod;
            return tmp;
        }
    }
    void build(int l,int r,int &x){
        if(!x)
            x = ++ tot;
        if(l == r){
            tree[x] = {1,ar[l],0,0,ar[l]};
            return;
        }
        int mid = (l + r) / 2;
        build(l,mid,ls(x)),build(mid + 1,r,rs(x));
        tree[x] = merge(x);
    }
    void modify(int l,int r,int x,int k,int val){
        if(l == r){
            tree[x].maxn = tree[x].hash = val;
            return;
        }
        int mid = (l + r) / 2;
        if(k <= mid)
            modify(l,mid,ls(x),k,val);
        else
            modify(mid + 1,r,rs(x),k,val);
        tree[x] = merge(x);
    }
};
void solve(){
    int n,m;
    cin>>n;
    vector<int>p(n + 1);
    for(int i = 1;i <= n;i ++)
        cin>>p[i];
    cin>>m;
    vector<int>q(m + 1);
    for(int i = 1;i <= m;i ++){
        cin>>q[i];
    }
    segtree A(n,p),B(m,q);
    int Q;
    cin>>Q;
    for(int i = 1;i <= Q;i ++){
        int opr,k,val;
        cin>>opr>>k>>val;
        if(opr == 1)
            A.modify(1,n,1,k,val);
        else
            B.modify(1,m,1,k,val);
        if(A.tree[A.rt].hash == B.tree[B.rt].hash && A.tree[A.rt].mxlen == B.tree[B.rt].mxlen)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }

}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    pre[0] = 1;
    for(int i = 1;i <= 100000;i ++){
        pre[i] = pre[i - 1] * A % mod; 
    }
    solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4400kb

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: 23ms
memory: 4348kb

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
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
YE...

result:

wrong answer 1st words differ - expected: 'NO', found: 'YES'