QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692202#8338. Quad Kingdoms Chesssnow_mikumikuWA 132ms9836kbC++143.8kb2024-10-31 14:03:472024-10-31 14:03:47

Judging History

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

  • [2024-10-31 14:03:47]
  • 评测
  • 测评结果:WA
  • 用时:132ms
  • 内存:9836kb
  • [2024-10-31 14:03:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using UL = unsigned long long;
const int N = 1e5 + 10;

UL m293[N], a[N], b[N];
struct tree {
    int l, r;
    UL cnt;
    UL max, hs, minstk;
    friend tree operator + (tree &a, tree &b) {
        tree ans;
        ans.cnt = a.cnt + b.cnt;
        ans.minstk = a.minstk;
        ans.max = b.max;
        ans.hs = a.hs * m293[b.cnt] + b.hs;
        return ans;
    }
}A[N << 3], B[N << 3], nul;

tree ask(int p, UL mx, int ty) 
{
    if(!ty) {
        if(!A[p].l) return nul;
        if(A[p].minstk >= mx) return A[p];
        if(A[p * 2].max >= mx) {
            tree tmp = ask(p * 2, mx, ty);
            return tmp + A[p * 2 + 1];
        }
        else return ask(p * 2 + 1, mx, ty);
    }

    else {
        if(!B[p].l) return nul;
        if(B[p].minstk >= mx) return B[p];
        if(B[p * 2].max >= mx) {
            tree tmp = ask(p * 2, mx, ty);
            return tmp + B[p * 2 + 1];
        }
        else return ask(p * 2 + 1, mx, ty);
    }
}


void update(int p, int ty)
{
    int ls = p * 2, rs = p * 2 + 1;
    if(!ty) {
        if(A[ls].max > A[rs].max) {
            A[p].cnt = A[ls].cnt;
            A[p].hs = A[ls].hs;
            A[p].max = A[ls].max;
            A[p].minstk = A[ls].minstk;
        }
        else {
            tree tmp = ask(rs, A[ls].max, ty);
            tmp = A[ls] + tmp;
            A[p].cnt = tmp.cnt;
            A[p].hs = tmp.hs;
            A[p].max = tmp.max;
            A[p].minstk = tmp.minstk;
        }
    }

    else {
        if(B[ls].max > B[rs].max) {
            B[p].cnt = B[ls].cnt;
            B[p].hs = B[ls].hs;
            B[p].max = B[ls].max;
            B[p].minstk = B[ls].minstk;
        }
        else {
            tree tmp = ask(rs, B[ls].max, ty);
            tmp = B[ls] + tmp;
            B[p].cnt = tmp.cnt;
            B[p].hs = tmp.hs;
            B[p].max = tmp.max;
            B[p].minstk = tmp.minstk;
        }
    }
}

void build(int l, int r, int p, int ty) 
{
    if(!ty) {
        A[p].l = l, A[p].r = r;
        if(l == r) {
            A[p].cnt = 1;
            A[p].max = A[p].hs = A[p].minstk = a[l];
            return;
        }
    }
    else {
        B[p].l = l, B[p].r = r;
        if(l == r) {
            B[p].cnt = 1;
            B[p].max = B[p].hs = B[p].minstk = b[l];
            return;
        }
    }
    int mid = l + r >> 1;
    build(l, mid, p * 2, ty);
    build(mid + 1, r, p * 2 + 1, ty);
    update(p, ty);
}

void change(int x, int p, UL To, int ty)
{
    if(!ty) {
        if(A[p].l == A[p].r && A[p].l == x) {
            A[p].hs = A[p].max = A[p].minstk = To;
            return;
        }
        int mid = A[p].l + A[p].r >> 1;
        if(x <= mid) change(x, p * 2, To, ty);
        else change(x, p * 2 + 1, To, ty);
        update(p, ty);
    }

    else {
        if(B[p].l == B[p].r) {
            B[p].hs = B[p].max = B[p].minstk = To;
            return;
        }
        int mid = B[p].l + B[p].r >> 1;
        if(x <= mid) change(x, p * 2, To, ty);
        else change(x, p * 2 + 1, To, ty);
        update(p, ty);
    }
}

int main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);

    m293[0] = 1;
    for(int i = 1; i < N; i++) m293[i] = m293[i - 1] * 293;
    int n, m, q;
    cin >> n;
    for(int i = n; i >= 1; i--) cin >> a[i];
    cin >> m;
    for(int i = m; i >= 1; i--) cin >> b[i];
    build(1, n, 1, 0);
    build(1, m, 1, 1);

    int op, x, y;
    cin >> q;
    for(int i = 1; i <= q; i++) {
        cin >> op >> x >> y;
        if(op == 1) x = n - x + 1, change(x, 1, y, 0);
        if(op == 2) x = m - x + 1, change(x, 1, y, 1);
        if(B[1].hs == A[1].hs) cout << "YES\n";
        else cout << "NO\n"; 
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 121ms
memory: 8480kb

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: 112ms
memory: 9796kb

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 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O
NO
NO
NO
NO
NO
NO
NO
NO
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:

wrong answer 123rd words differ - expected: 'YES', found: 'NO'