QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760643#6608. Descent of DragonsAlorithmRE 52ms22916kbC++172.6kb2024-11-18 18:09:072024-11-18 18:09:09

Judging History

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

  • [2024-11-18 18:09:09]
  • 评测
  • 测评结果:RE
  • 用时:52ms
  • 内存:22916kb
  • [2024-11-18 18:09:07]
  • 提交

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];
        return u;
    }

    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;
        }

        u = clone_node(u);

        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: 5260kb

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: 0
Accepted
time: 1ms
memory: 5584kb

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
2
2
2
2
3
1
3
2
2
3
3
2
2
1
3
2
3
3
3
3
3
3
3
2
2
3
3
2
3
2
1
3
3
2
1
3
3
3
1
1
2
2
3
2
1
1
3
3
2
2
2
3
2
3
2
3
2
2
3
3
2
2
1
2
3
2
3
4
4
4
4
2
4
2
4
4
4
...

result:

ok 198 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 5464kb

input:

1000 1000
1 26 189 2
1 485 923 7
1 108 839 9
1 200 260 8
1 196 296 1
1 894 897 7
1 215 510 3
1 117 333 9
2 395 646
1 548 762 8
1 317 340 0
1 354 879 0
1 294 373 8
1 277 979 5
1 10 295 8
2 769 784
1 271 850 4
1 233 440 4
1 416 542 3
1 454 470 7
1 439 956 5
1 644 722 1
1 732 951 4
1 423 768 5
1 43 962...

output:

0
1
1
1
1
1
3
3
3
3
3
3
3
3
3
5
4
5
4
5
1
5
5
1
6
6
6
6
7
7
6
7
6
7
7
10
10
10
10
10
10
10
8
10
8
8
10
10
5
10
10
10
10
10
10
10
5
6
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10...

result:

ok 197 numbers

Test #4:

score: 0
Accepted
time: 1ms
memory: 5428kb

input:

1000 1000
1 646 946 11
1 192 372 8
1 14 516 45
2 664 910
1 164 693 0
1 285 411 16
1 682 888 40
2 153 569
1 407 481 18
1 961 985 4
1 22 904 11
1 195 213 34
2 46 767
1 73 106 5
1 172 573 38
1 277 322 9
1 230 555 29
1 882 882 18
1 140 276 7
1 15 102 21
1 319 383 29
1 289 814 22
1 795 905 45
1 205 415 3...

output:

0
1
1
1
1
0
1
1
0
1
1
1
1
0
1
1
0
1
1
3
0
1
0
3
2
3
1
1
0
1
3
3
1
1
1
1
3
3
0
3
3
1
0
3
0
3
3
3
3
1
1
3
3
1
0
3
3
3
3
1
2
4
4
4
4
2
2
4
2
0
3
5
4
5
4
5
5
5
5
0
5
5
0
5
5
5
4
5
5
2
5
5
5
5
6
4
5
5
6
5
6
6
6
6
0
5
6
6
6
6
6
6
6
6
6
1
6
6
6
6
6
8
7
8
8
7
8
3
3
8
3
7
8
8
8
8
6
7
7
1
1
9
9
9
8
9
9
9
8
9
...

result:

ok 187 numbers

Test #5:

score: 0
Accepted
time: 52ms
memory: 22916kb

input:

70000 80000
2 9805 11304
1 2826 15704 47
1 13625 31020 42
1 13179 20404 49
1 10844 24118 49
1 5973 11929 1
1 26374 29887 7
1 12989 17431 46
1 5119 9903 44
1 12753 18942 7
2 12261 29009
1 1028 15183 30
1 2757 18390 35
1 5345 15962 24
1 1488 15535 42
1 23143 30796 19
2 15847 29111
1 3632 12377 38
1 31...

output:

0
0
0
0
1
1
1
1
1
0
1
1
1
0
0
2
0
2
2
2
0
2
2
2
2
2
1
2
2
2
3
3
3
1
3
3
3
3
0
4
4
4
3
4
4
4
4
4
4
4
4
3
4
2
2
2
5
5
5
5
5
3
5
5
5
5
5
3
5
5
3
5
5
5
3
5
5
5
5
5
5
5
5
3
3
3
3
6
0
6
3
6
3
6
6
6
4
3
1
7
7
7
4
4
7
7
1
7
7
7
4
7
1
7
1
7
1
4
4
7
4
7
4
4
7
7
7
4
4
5
6
6
4
3
3
4
8
9
4
9
10
7
11
11
11
11
3
1...

result:

ok 16106 numbers

Test #6:

score: 0
Accepted
time: 19ms
memory: 5168kb

input:

700 100000
1 106 184 1711
1 455 503 1417
2 14 181
1 292 327 1563
1 54 457 88
1 99 124 1077
1 177 290 1016
1 174 615 605
2 166 641
1 368 431 492
1 118 416 1747
1 179 431 1019
1 101 525 860
1 331 670 1482
1 170 336 1031
1 20 310 1961
2 144 179
2 247 505
1 219 693 1602
1 355 602 485
1 33 117 1344
1 198...

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
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
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
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
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 20052 numbers

Test #7:

score: -100
Runtime Error

input:

789 99938
2 422 480
1 504 725 222
1 189 379 3
2 48 266
2 417 466
1 665 692 242
1 433 457 88
1 161 462 172
1 240 785 386
1 198 315 421
1 31 605 58
1 259 703 125
1 449 566 122
1 237 478 336
1 500 580 4
2 281 499
2 375 743
2 442 588
1 345 417 103
2 292 400
1 128 503 115
1 680 711 560
2 244 781
1 123 78...

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
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
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
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
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
0
0
1
1
0
1
1
1
1
0
0
...

result: