QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591346#8338. Quad Kingdoms ChessRosmontispesWA 97ms4596kbC++203.5kb2024-09-26 15:30:272024-09-26 15:30:27

Judging History

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

  • [2024-09-26 15:30:27]
  • 评测
  • 测评结果:WA
  • 用时:97ms
  • 内存:4596kb
  • [2024-09-26 15:30:27]
  • 提交

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];
long long qpow(long long x,long long t){
    if(t == 0)
        return 1;
    else {
        if(t % 2 == 0){
            long long tmp = qpow(x,t / 2);
            return tmp * tmp % mod;
        } else {
            return qpow(x,t - 1) * x % mod;
        }
    }
}
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].ls && !tree[x].rs)
            return {tree[x].mxlen,tree[x].hash};
        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 + mod) % mod * qpow(tree[rs(x)].mxlen,mod - 2) % mod * pre[rret.first] % mod + rret.second) % 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();
}

Details

Tip: Click on the bar to expand more detailed information

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: 0
Accepted
time: 67ms
memory: 4344kb

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:

ok 200000 tokens

Test #3:

score: 0
Accepted
time: 65ms
memory: 4596kb

input:

6
2 1 1 2 1 2
1
1
200000
2 1 1
1 1 2
1 1 1
2 1 2
2 1 1
2 1 1
2 1 2
2 1 2
1 1 2
1 3 1
1 6 2
1 5 2
1 4 2
1 3 1
2 1 2
1 4 2
1 4 2
2 1 2
2 1 2
1 3 1
1 6 1
1 1 2
2 1 1
1 6 1
1 3 1
1 5 2
1 6 2
1 5 2
2 1 2
1 2 1
1 5 2
2 1 1
2 1 1
1 6 1
2 1 2
2 1 1
1 3 2
2 1 1
1 6 1
1 4 2
1 2 1
1 1 1
2 1 1
1 2 1
1 6 2
1 6 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:

ok 200000 tokens

Test #4:

score: -100
Wrong Answer
time: 97ms
memory: 4408kb

input:

6
1 3 1 2 1 2
6
2 1 3 3 3 1
200000
2 4 2
1 2 1
1 6 2
2 3 2
1 1 1
1 6 2
1 6 2
1 3 2
2 6 1
2 4 3
1 1 2
2 5 2
2 6 2
2 3 1
1 4 3
1 3 1
2 5 2
2 4 2
2 1 3
1 1 1
2 2 2
2 4 2
1 5 3
1 6 3
2 6 3
1 5 3
2 5 3
2 4 1
2 4 2
1 1 2
1 6 1
2 6 1
1 2 3
1 1 3
1 1 1
2 6 3
2 4 1
1 4 2
2 2 1
1 3 1
1 1 3
1 1 3
1 4 3
1 3 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 27th words differ - expected: 'YES', found: 'NO'