QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#18627#2327. Egma GameDoorKickersRE 3ms3656kbC++202.4kb2022-01-22 15:23:132022-05-06 01:55:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-06 01:55:30]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:3656kb
  • [2022-01-22 15:23:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// #define int long long
struct info {
    int lson, rson, num;
    info() : lson(0), rson(0), num(0) {}
    info(int lson, int rson, int num) : lson(lson), rson(rson), num(num) {}
};
struct segment_tree {
    int tot; vector<int> root;
    vector<info> tr;
    segment_tree(int n, int m) : tr(n * 30 + 5), tot(0), root(m + 5) {}
    int insert(int p, int l, int r, int x, int idx) {
        int q = ++tot;
        tr[q] = tr[p];
        if (l == r) {
            tr[q].num = idx;
            return q;
        }
        int mid = (l + r) >> 1;
        if (x <= mid) tr[q].lson = insert(tr[p].lson, l, mid, x, idx);
        else tr[q].rson = insert(tr[p].rson, mid + 1, r, x, idx);
        tr[q].num = min(tr[tr[q].lson].num, tr[tr[q].rson].num);
        return q;
    }
    int query(int q, int p, int l, int r) {
        if (l == r) return l;
        int mid = (l + r) >> 1;
        if (tr[tr[p].lson].num < q) return query(q, tr[p].lson, l, mid);
        else return query(q, tr[p].rson, mid + 1, r);
    }
    void debug(int p, int l, int r, int idx) {
        cout << "tree " << idx << "'s " << l << ' ' << r << "has num = " << tr[p].num << '\n';
        // cout << "tree " << idx << "'s " << tr[p].lson << ' ' << tr[p].rson << "is " << tr[tr[p].lson].num << ' ' << tr[tr[p].rson].num << '\n';
        if (l == r) return;
        int mid = (l + r) >> 1;
        debug(tr[p].lson, l, mid, idx);
        debug(tr[p].rson, mid + 1, r, idx);
    }
};
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    map<int, bool> vis;
    vector<int> a(n + 5);
    int mx(0), piv(-1);
    for (int i = 1; i <= n; i++) {cin >> a[i]; vis[a[i]] = 1; mx = max(mx, a[i]);}
    for (int i = 0; i <= mx + 1; i++) {
        if (!vis[i]) {piv = i; break;}
    }
    segment_tree tree(piv + 2, n + 2);
    // cout << "piv = " << piv << '\n';
    for (int i = 1; i <= n; i++) {
        if (a[i] > piv) {tree.root[i] = tree.root[i - 1]; continue;}
        tree.root[i] = tree.insert(tree.root[i - 1], 0, piv, a[i], i);
        // tree.debug(tree.root[i], 0, piv, i);
    }
    int q; cin >> q;
    for (int i = 1; i <= q; i++) {
        int l, r; cin >> l >> r;
        if (piv == 0) cout << 0 << '\n';
        else {
            cout << tree.query(l, tree.root[r], 0, piv) << '\n';
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3616kb

input:

5
1 2 3 0 5
2
1 3
1 4

output:

0
4

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 3656kb

input:

20
2 6 8 3 2 1 0 6 3 9 5 7 4 5 1 5 6 6 8 1
6
3 11
3 19
8 8
17 17
18 20
19 20

output:

4
10
0
0
0
0

result:

ok 6 lines

Test #3:

score: 0
Accepted
time: 3ms
memory: 3656kb

input:

2
1000000000 0
2
1 1
1 2

output:

0
1

result:

ok 2 lines

Test #4:

score: -100
Runtime Error

input:

500000
113500 171767 129776 204668 144688 243684 196619 110568 150466 2356 26733 173616 239824 118055 28013 96287 207607 5877 192363 187149 87221 38182 50377 131406 58562 103473 43635 208503 139095 174585 97707 35920 162202 107727 231465 137612 54481 84944 2478 171891 68834 26296 115626 35312 44152 ...

output:


result: