QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#784496#8338. Quad Kingdoms ChessZeoyRE 0ms0kbC++202.2kb2024-11-26 15:10:192024-11-26 15:10:22

Judging History

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

  • [2024-11-26 15:10:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-26 15:10:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
const int N = 100010;
mt19937_64 rnd(time(0));

int n1, n2, q, a[N], b[N];
ull hs[N];

struct SegmentTree {
    int mx[N << 2];
    ull shs[N << 2]; // sum of hs
    #define lson (id << 1)
    #define rson (id << 1 | 1)
    #define mid ((l + r) >> 1)
    ull qry(int id, int l, int r, int k) {
        if (mx[id] < k) return 0ULL;
        if (l == r) return (mx[id] >= k ? shs[id] : 0ULL);
        if (mx[rson] >= k) return qry(rson, mid + 1, r, k) + shs[id] - shs[rson];
        else qry(lson, l, mid, k); 
    }
    void up(int id, int l, int r) {
        mx[id] = max(mx[lson], mx[rson]);
        shs[id] = qry(lson, l, mid, mx[rson]) + shs[rson];
    }
    void build(int id, int l, int r, int *a) {
        if (l == r) {
            mx[id] = a[l];
            shs[id] = hs[a[l]];
            return;
        }
        build(lson, l, mid, a), build(rson, mid + 1, r, a);
        up(id, l, r);
    }
    void modify(int id, int l, int r, int x, int v) {
        if (l == r) {
            mx[id] = v;
            shs[id] = hs[v];
            return;
        }
        if (x <= mid) modify(lson, l, mid, x, v);
        else modify(rson, mid + 1, r, x, v);
        up(id, l, r);
    }
    #undef lson
    #undef rson
    #undef mid
} T[2];

void solve() {
    for (int i = 1; i <= 100000; ++i) hs[i] = rnd();
    cin >> n1;
    for (int i = 1; i <= n1; ++i) {
        cin >> a[i];
    }
    cin >> n2;
    for (int i = 1; i <= n2; ++i) {
        cin >> b[i];
    }
    T[0].build(1, 1, n1, a);
    T[1].build(1, 1, n2, b);
    cin >> q;
    while (q--) {
        int op, x, y; cin >> op >> x >> y;
        if (op == 1) {
            T[0].modify(1, 1, n1, x, y);
        } else {
            T[1].modify(1, 1, n2, x, y);
        }
        if (T[0].shs[1] == T[1].shs[1]) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
}
signed main(void) {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int Test = 1;
    // cin >> Test;
    while (Test--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:


result: