QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760620#6608. Descent of DragonsAlorithmWA 2ms5588kbC++172.6kb2024-11-18 17:56:582024-11-18 17:56:59

Judging History

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

  • [2024-11-18 17:56:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5588kb
  • [2024-11-18 17:56:58]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using i64 = long long;

struct SegTree {
    int n, cnt;
    vector<bool> val;
    vector<int> ls, rs;

    SegTree(int N = 0) : n(N) {
        cnt = 0;
        val.resize(n << 5);
        ls.resize(n << 5);
        rs.resize(n << 5);
    }

    int new_node() {
        return ++cnt;
    }

    int clone_node(int p) {
        int u = new_node();
        val[u] = val[p];
        ls[u] = ls[p];
        rs[u] = rs[p];
    }

    void updata(int p) {
        val[p] = val[ls[p]] | val[rs[p]];
    }

    void build(int& p, int l, int r) {
        if (!p)
            p = new_node();

        if (l == r) {
            val[p] = true;
            return;
        }

        int mid = (l + r) >> 1;
        build(ls[p], l, mid);
        build(rs[p], mid + 1, r);
        updata(p);
    }

    void copy(int s, int t, int& u, int& v, int l, int r) {
        if (!v)
            return;

        if (s <= l && r <= t) {
            u = v;
            return;
        }

        if (!u)
            u = new_node();

        int mid = (l + r) >> 1;
        if (s <= mid)
            copy(s, t, ls[u], ls[v], l, mid);
        if (mid + 1 <= t)
            copy(s, t, rs[u], rs[v], mid + 1, r);
        updata(u);
    }

    bool query(int s, int t, int p, int l, int r) {
        if (!p)
            return false;

        if (s <= l && r <= t)
            return val[p];

        int mid = (l + r) >> 1;
        bool res = false;
        if (s <= mid)
            res |= query(s, t, ls[p], l, mid);
        if (mid + 1 <= t)
            res |= query(s, t, rs[p], mid + 1, r);
        return res;
    }
};

const int MAXN = 5e5 + 5;

void solve() {
    int n, q;
    cin >> n >> q;

    SegTree tr(n);
    vector<int> root(MAXN);
    tr.build(root[0], 1, n);

    while (q--) {
        int op;
        cin >> op;
        if (op == 1) {
            int l, r, x;
            cin >> l >> r >> x;
            tr.copy(l, r, root[x + 1], root[x], 1, n);
        }
        if (op == 2) {
            int s, t;
            cin >> s >> t;
            int l = 0, r = MAXN - 4;
            while (l <= r) {
                int mid = (l + r) >> 1;
                if (tr.query(s, t, root[mid], 1, n))
                    l = mid + 1;
                else
                    r = mid - 1;
            }
            cout << r << endl;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 5
1 3 5 0
1 1 4 1
1 1 5 2
2 2 2
2 4 5

output:

0
3

result:

ok 2 number(s): "0 3"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 5588kb

input:

1000 1000
2 234 913
1 693 735 47
1 702 959 94
2 273 286
1 814 896 47
1 560 566 15
1 46 699 97
2 494 527
1 721 879 68
1 87 437 26
1 163 938 15
1 816 912 58
2 284 670
2 713 763
1 49 542 13
1 669 874 41
2 795 855
1 601 962 93
1 413 747 50
1 528 710 73
2 255 435
1 329 871 86
1 24 236 48
1 22 48 41
1 29 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
1
0
0
0
0
0
2
2
0
2
0
0
0
0
2
0
2
2
2
2
2
2
2
2
2
2
0
0
2
0
0
0
3
3
3
0
0
0
1
1
1
3
3
2
2
3
3
1
3
2
3
3
3
3
3
1
3
2
3
3
3
3
3
3
3
3
2
3
3
3
3
2
3
3
3
2
1
3
3
3
1
1
3
2
3
3
1
1
3
3
2
3
3
3
3
3
3
3
2
2
3
3
2
3
1
3
3
2
3
4
4
4
4
2
4
2
4
4
4
...

result:

wrong answer 74th numbers differ - expected: '2', found: '3'