Submission #987245

# Submission time Handle Problem Language Result Execution time Memory
987245 2024-05-22T12:27:05 Z vjudge1 Inspections (NOI23_inspections) C++17
100 / 100
398 ms 29236 KB
#include <bits/stdc++.h>
using namespace std;

struct range {
    long long l, r, val = -1e18;
    range() {}
    range(long long _l, long long _r, long long _val) {
        l = _l;
        r = _r;
        val = _val;
    }
    friend bool operator<(const range& a, const range& b) {
        return b.r > a.r;
    }
};

set<range> s;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<pair<long long, long long>> p(m), qs;
    vector<long long> pref(m, 0);

    for (int i = 0; i < m; i++) {
        cin >> p[i].first >> p[i].second;
        pref[i] = p[i].second - p[i].first + 1;
        if (i) pref[i] += pref[i - 1];
    }

    for (int i = 0; i < q; i++) {
        long long x;
        cin >> x;
        qs.push_back({x, i});
    }

    sort(qs.begin(), qs.end());

    vector<long long> ans(q, 0);
    s.insert(range(1, n, -1e18));

    for (int i = 0; i < m; i++) {
        long long l0 = p[i].first;
        long long r0 = p[i].second;
        vector<range> add;
        add.push_back(range(l0, r0, r0 - pref[i]));

        while (true) {
            auto it = s.upper_bound(range(0, l0 - 1, 0));
            if (it == s.end()) break;
            if (it->l > r0) break;
            if (it->l < l0) add.push_back(range(it->l, l0 - 1, it->val));
            if (it->r > r0) add.push_back(range(r0 + 1, it->r, it->val));

            long long inter = min(r0, it->r) - max(l0, it->l) + 1;
            long long gap = (i ? pref[i - 1] : 0) - l0 + it->val + 1;
            int idx = lower_bound(qs.begin(), qs.end(), make_pair(gap, 0LL)) - qs.begin() - 1;
            if (idx >= 0) ans[idx] += inter;
            s.erase(it);
        }

        for (auto x : add) s.insert(x);
    }

    for (int i = q - 2; i >= 0; i--) ans[i] += ans[i + 1];
    vector<long long> fin(q);

    for (int i = 0; i < q; i++) fin[qs[i].second] = ans[i];

    for (int i = 0; i < q; i++) cout << fin[i] << " ";
    cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 77 ms 8772 KB Output is correct
14 Correct 74 ms 8352 KB Output is correct
15 Correct 80 ms 8632 KB Output is correct
16 Correct 78 ms 8832 KB Output is correct
17 Correct 77 ms 8600 KB Output is correct
18 Correct 80 ms 8564 KB Output is correct
19 Correct 75 ms 8592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 76 ms 8564 KB Output is correct
4 Correct 109 ms 9100 KB Output is correct
5 Correct 234 ms 16236 KB Output is correct
6 Correct 198 ms 15804 KB Output is correct
7 Correct 150 ms 14184 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 77 ms 8772 KB Output is correct
14 Correct 74 ms 8352 KB Output is correct
15 Correct 80 ms 8632 KB Output is correct
16 Correct 78 ms 8832 KB Output is correct
17 Correct 77 ms 8600 KB Output is correct
18 Correct 80 ms 8564 KB Output is correct
19 Correct 75 ms 8592 KB Output is correct
20 Correct 80 ms 9656 KB Output is correct
21 Correct 78 ms 8884 KB Output is correct
22 Correct 77 ms 9716 KB Output is correct
23 Correct 74 ms 8948 KB Output is correct
24 Correct 75 ms 8636 KB Output is correct
25 Correct 86 ms 9140 KB Output is correct
26 Correct 74 ms 9652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 77 ms 8772 KB Output is correct
14 Correct 74 ms 8352 KB Output is correct
15 Correct 80 ms 8632 KB Output is correct
16 Correct 78 ms 8832 KB Output is correct
17 Correct 77 ms 8600 KB Output is correct
18 Correct 80 ms 8564 KB Output is correct
19 Correct 75 ms 8592 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 76 ms 8564 KB Output is correct
23 Correct 109 ms 9100 KB Output is correct
24 Correct 234 ms 16236 KB Output is correct
25 Correct 198 ms 15804 KB Output is correct
26 Correct 150 ms 14184 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 80 ms 9656 KB Output is correct
30 Correct 78 ms 8884 KB Output is correct
31 Correct 77 ms 9716 KB Output is correct
32 Correct 74 ms 8948 KB Output is correct
33 Correct 75 ms 8636 KB Output is correct
34 Correct 86 ms 9140 KB Output is correct
35 Correct 74 ms 9652 KB Output is correct
36 Correct 307 ms 16828 KB Output is correct
37 Correct 310 ms 17124 KB Output is correct
38 Correct 261 ms 16828 KB Output is correct
39 Correct 239 ms 16576 KB Output is correct
40 Correct 287 ms 16572 KB Output is correct
41 Correct 314 ms 21948 KB Output is correct
42 Correct 309 ms 22716 KB Output is correct
43 Correct 329 ms 29236 KB Output is correct
44 Correct 339 ms 29148 KB Output is correct
45 Correct 300 ms 16360 KB Output is correct
46 Correct 398 ms 18364 KB Output is correct
47 Correct 336 ms 18976 KB Output is correct
48 Correct 264 ms 17080 KB Output is correct