Submission #828851

# Submission time Handle Problem Language Result Execution time Memory
828851 2023-08-17T17:36:09 Z t6twotwo Inspections (NOI23_inspections) C++17
100 / 100
684 ms 37264 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> l(m), r(m);
    vector<ll> pfs(m + 1);
    vector<vector<pair<int, int>>> T(n + 1);
    for (int i = 0; i < m; i++) {
        cin >> l[i] >> r[i];
        l[i]--;
        T[l[i]].emplace_back(0, i);
        T[r[i]].emplace_back(1, i);
        pfs[i + 1] = pfs[i] + r[i] - l[i];
    }
    vector<ll> s(q);
    for (ll &x : s) {
        cin >> x;
    }
    vector<int> p(q);
    iota(p.begin(), p.end(), 0);
    sort(p.begin(), p.end(), [&](int i, int j) {
        return s[i] < s[j];
    });
    set<tuple<int, int, int>> t;
    auto get = [&](int x, int y) {
        return lower_bound(p.begin(), p.end(), pfs[y] - pfs[x + 1] + r[x] - l[y], [&](int i, ll j) {
            return s[i] < j;
        }) - p.begin();
    };
    vector<ll> f(q + 1);
    for (int i = 0; i <= n; i++) {
        for (auto [z, k] : T[i]) {
            if (z == 0) {
                auto it = t.upper_bound({k, -1, -1});
                if (it != t.begin() && it != t.end()) {
                    auto [i0, l0, r0] = *prev(it);
                    auto [i1, l1, r1] = *it;
                    assert(r0 == l1);
                    t.erase({i0, l0, r0});
                    t.erase({i1, l1, r1});
                    t.emplace(k, i, i);
                    t.emplace(i0, l0, i);
                    t.emplace(i1, i, r1);
                    f[get(i0, i1)] += i - r0;
                } else if (t.empty()) {
                    t.emplace(k, -1, -1);
                } else if (it == t.begin()) {
                    auto [i1, l1, r1] = *it;
                    t.erase(it);
                    t.emplace(k, -1, i);
                    t.emplace(i1, i, r1);
                } else {
                    auto [i0, l0, r0] = *prev(it);
                    t.erase(prev(it));
                    t.emplace(k, i, -1);
                    t.emplace(i0, l0, i);
                }
            } else {
                auto it = t.lower_bound({k, -1, -1});
                if (it != t.begin() && next(it) != t.end()) {
                    auto [_, l, r] = *it;
                    auto [i0, l0, r0] = *prev(it);
                    auto [i1, l1, r1] = *next(it);
                    assert(l == r0);
                    assert(r == l1);
                    f[get(i0, k)] += i - r0;
                    f[get(k, i1)] += i - l1;
                    t.erase(it);
                    t.erase({i0, l0, r0});
                    t.erase({i1, l1, r1});
                    t.emplace(i0, l0, i);
                    t.emplace(i1, i, r1);
                } else if (t.size() == 1) {
                    t.erase(it);
                } else if (it == t.begin()) {
                    auto [_, l, r] = *it;
                    auto [i1, l1, r1] = *next(it);
                    assert(r == l1);
                    f[get(k, i1)] += i - l1;
                    t.erase(it);
                    t.erase({i1, l1, r1});
                    t.emplace(i1, -1, r1);
                } else {
                    auto [_, l, r] = *it;
                    auto [i0, l0, r0] = *prev(it);
                    assert(l == r0);
                    f[get(i0, k)] += i - r0;
                    t.erase(it);
                    t.erase({i0, l0, r0});
                    t.emplace(i0, l0, -1);
                }
            }
        }
    }
    vector<ll> ans(q);
    for (int i = q - 1; i >= 0; i--) {
        ans[p[i]] = f[i + 1];
        f[i] += f[i + 1];
    }
    for (int i = 0; i < q; i++) {
        cout << ans[i] << " \n"[i == q - 1];
    }
    return 6/22;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 48 ms 7896 KB Output is correct
14 Correct 43 ms 7408 KB Output is correct
15 Correct 48 ms 7900 KB Output is correct
16 Correct 46 ms 7988 KB Output is correct
17 Correct 45 ms 7780 KB Output is correct
18 Correct 46 ms 7944 KB Output is correct
19 Correct 46 ms 8088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 46 ms 7884 KB Output is correct
4 Correct 53 ms 13148 KB Output is correct
5 Correct 466 ms 35236 KB Output is correct
6 Correct 423 ms 34952 KB Output is correct
7 Correct 262 ms 26688 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 48 ms 7896 KB Output is correct
14 Correct 43 ms 7408 KB Output is correct
15 Correct 48 ms 7900 KB Output is correct
16 Correct 46 ms 7988 KB Output is correct
17 Correct 45 ms 7780 KB Output is correct
18 Correct 46 ms 7944 KB Output is correct
19 Correct 46 ms 8088 KB Output is correct
20 Correct 51 ms 13772 KB Output is correct
21 Correct 47 ms 12860 KB Output is correct
22 Correct 49 ms 13760 KB Output is correct
23 Correct 46 ms 12748 KB Output is correct
24 Correct 46 ms 12460 KB Output is correct
25 Correct 57 ms 13200 KB Output is correct
26 Correct 48 ms 13388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 48 ms 7896 KB Output is correct
14 Correct 43 ms 7408 KB Output is correct
15 Correct 48 ms 7900 KB Output is correct
16 Correct 46 ms 7988 KB Output is correct
17 Correct 45 ms 7780 KB Output is correct
18 Correct 46 ms 7944 KB Output is correct
19 Correct 46 ms 8088 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 46 ms 7884 KB Output is correct
23 Correct 53 ms 13148 KB Output is correct
24 Correct 466 ms 35236 KB Output is correct
25 Correct 423 ms 34952 KB Output is correct
26 Correct 262 ms 26688 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 320 KB Output is correct
29 Correct 51 ms 13772 KB Output is correct
30 Correct 47 ms 12860 KB Output is correct
31 Correct 49 ms 13760 KB Output is correct
32 Correct 46 ms 12748 KB Output is correct
33 Correct 46 ms 12460 KB Output is correct
34 Correct 57 ms 13200 KB Output is correct
35 Correct 48 ms 13388 KB Output is correct
36 Correct 684 ms 25608 KB Output is correct
37 Correct 632 ms 31096 KB Output is correct
38 Correct 486 ms 30648 KB Output is correct
39 Correct 246 ms 23884 KB Output is correct
40 Correct 450 ms 36340 KB Output is correct
41 Correct 277 ms 37084 KB Output is correct
42 Correct 275 ms 37264 KB Output is correct
43 Correct 266 ms 36300 KB Output is correct
44 Correct 264 ms 36120 KB Output is correct
45 Correct 414 ms 25660 KB Output is correct
46 Correct 368 ms 25716 KB Output is correct
47 Correct 299 ms 25988 KB Output is correct
48 Correct 529 ms 32988 KB Output is correct