QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876183#8612. The Best Wifesuperguymj#WA 0ms3712kbC++202.7kb2025-01-30 18:08:272025-01-30 18:08:28

Judging History

This is the latest submission verdict.

  • [2025-01-30 18:08:28]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3712kb
  • [2025-01-30 18:08:27]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;

struct Block {
    const int N, B;
    vector<int> range;
    struct J {
        int nextr, step, pos;
        J(int nextr = inf, int step = 0, int pos = -1)
            : nextr(nextr), step(step), pos(pos) {}
        friend ostream &operator<<(ostream &out, J &j) {
            out << "{" << j.nextr << ' ' << j.step << ' ' << j.pos << "}";
            return out;
        }
    };
    vector<J> jump;
    Block(int n)
        : N(n), B(max(1, (int)sqrtl(n))), range(n + 1, n + 1), jump(n + 1) {
        for (int i = n / B; i >= 0; i--) {
            build(i);
        }
    }
    void build(int x, int pos = inf) {
        int l = x * B, r = min(N, l + B - 1);
        pos = min(pos, r);
        for (int i = pos; i >= l; i--) {
            if (i == r) {
                jump[i] = J(N + 2, 0, N + 2);
            } else {
                jump[i] = jump[i + 1];
            }
            if (range[i] + 1 < jump[i].nextr) {
                jump[i].nextr = range[i] + 1;
                if (range[i] + 1 <= r) {
                    jump[i].step = jump[range[i] + 1].step + 1;
                    jump[i].pos = jump[range[i] + 1].pos;
                } else {
                    jump[i].step = 1;
                    jump[i].pos = range[i] + 1;
                }
            }
        }
#ifdef DEBUG
        cerr << "build block " << x << '\n';
        for (int i = l; i <= r; i++) {
            cerr << jump[i] << ' ';
        }
        cerr << endl;
#endif
    }
    void add(int l, int r) {
        range[l] = min(range[l], r);
        build(l / B, l);
    }
    int query() const {
        int res = 0, lst = 0, pos = N + 2;
        for (int i = 0; i <= N / B; i++) {
            if (jump[i * B].nextr < pos) {
                res += max(lst - 1, 0);
                lst = jump[i * B].step;
                pos = jump[i * B].pos;
            } else if (pos <= N && pos / B == i) {
                res += lst;
                lst = jump[pos].step;
                pos = jump[pos].pos;
            }
#ifdef DEBUG
            cerr << "block " << i << ": res = " << res << ", pos = " << pos
                 << endl;
#endif
        }
        return res + lst;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<int, int>> p(n);
    int mx = 0;
    for (auto &[l, r] : p) {
        cin >> l >> r;
        mx = max(mx, r);
    }
    Block b(mx);
#ifdef DEBUG
    cerr << "block size = " << b.B << endl;
#endif
    for (int i = 0; i < n; i++) {
        b.add(p[i].first, p[i].second);
        cout << b.query() << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 3
3 5
1 2
5 6
4 4

output:

1
1
2
2
3

result:

ok 5 number(s): "1 1 2 2 3"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3712kb

input:

100
67 72
1 100
61 65
87 91
19 77
47 97
3 85
64 97
6 92
33 36
7 27
33 44
13 98
3 62
36 97
26 39
7 35
2 92
8 64
37 83
5 89
26 87
6 96
58 71
49 96
3 85
27 65
16 93
26 70
8 97
1 100
8 93
5 59
9 92
9 99
1 100
8 81
7 66
4 78
12 52
28 42
1 36
2 100
75 81
26 61
8 86
4 44
58 74
29 100
40 77
83 100
39 59
3 9...

output:

1
1
2
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
6
6
6
6
6
6
6
6
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
9
9
9
9
9
9
9
9
9
9
10
10

result:

wrong answer 10th numbers differ - expected: '4', found: '3'