Submission #1097981

# Submission time Handle Problem Language Result Execution time Memory
1097981 2024-10-08T17:49:30 Z VMaksimoski008 Inspections (NOI23_inspections) C++17
100 / 100
431 ms 28344 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

vector<pll> qus;

int bin_search(ll p) {
    int l=0, r=qus.size()-1, ans=-1;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(qus[mid].first <= p) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}

int main() {
    int n, m, q; cin >> n >> m >> q;
    ll day = 1;

    vector<int> L(m), R(m);
    for(int i=0; i<m; i++) cin >> L[i] >> R[i];

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

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

    vector<ll> ans(q);
    set<array<ll, 3> > s;

    for(int i=0; i<m; i++) {
        vector<array<ll, 3> > to_rem, to_add;
        
        auto it = s.lower_bound({ L[i], 0, 0 });
        if(it != s.begin()) --it;
        while(it != s.end()) {
            auto [l, r, x] = *it;
            if(l > R[i]) break;
            if(L[i] <= l && r <= R[i]) {
                int p = bin_search(day + l - L[i] - x - 1);
                if(p > -1) ans[p] += r - l + 1;
                to_rem.push_back({ l, r, x });
            } else if(l < L[i] && R[i] < r) {
                int p = bin_search(day - (x + L[i] - l) - 1);
                if(p > -1) ans[p] += R[i] - L[i] + 1;
                to_rem.push_back({ l, r, x });
                to_add.push_back({ l, L[i]-1, x });
                to_add.push_back({ R[i]+1, r, R[i] + 1 - l + x});
            } else if(l < L[i] && L[i] <= r && r <= R[i]) {
                int p = bin_search(day - (x + L[i] - l) - 1);
                if(p > -1) ans[p] += r - L[i] + 1;
                to_rem.push_back({ l, r, x });
                to_add.push_back({ l, L[i]-1, x });
            } else if(L[i] <= l && l <= R[i] && R[i] < r) {
                int p = bin_search(day + l - L[i] - x - 1);
                if(p > -1) ans[p] += R[i] - l + 1;
                to_rem.push_back({ l, r, x });
                to_add.push_back({ R[i]+1, r, R[i] + 1 - l + x });
            }
            ++it;
        }

        to_add.push_back({ L[i], R[i], day });
        for(auto &x : to_rem) s.erase(x);
        for(auto &x : to_add) s.insert(x);
        day += R[i] - L[i] + 1;
    }


    for(int i=q-2; i>=0; i--) ans[i] += ans[i+1];
    for(int i=0; i<q; i++) qus[i].first = ans[i];
    sort(qus.begin(), qus.end(), [&](pll a, pll b) { return a.second < b.second; });
    for(auto x : qus) cout << x.first << " ";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 81 ms 5348 KB Output is correct
14 Correct 86 ms 5304 KB Output is correct
15 Correct 79 ms 5488 KB Output is correct
16 Correct 81 ms 5936 KB Output is correct
17 Correct 79 ms 5400 KB Output is correct
18 Correct 83 ms 5560 KB Output is correct
19 Correct 76 ms 5816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 78 ms 5500 KB Output is correct
4 Correct 89 ms 5716 KB Output is correct
5 Correct 216 ms 8256 KB Output is correct
6 Correct 193 ms 6984 KB Output is correct
7 Correct 146 ms 8376 KB Output is correct
8 Correct 0 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 81 ms 5348 KB Output is correct
14 Correct 86 ms 5304 KB Output is correct
15 Correct 79 ms 5488 KB Output is correct
16 Correct 81 ms 5936 KB Output is correct
17 Correct 79 ms 5400 KB Output is correct
18 Correct 83 ms 5560 KB Output is correct
19 Correct 76 ms 5816 KB Output is correct
20 Correct 78 ms 6784 KB Output is correct
21 Correct 75 ms 6060 KB Output is correct
22 Correct 81 ms 6824 KB Output is correct
23 Correct 75 ms 6068 KB Output is correct
24 Correct 76 ms 5684 KB Output is correct
25 Correct 94 ms 5816 KB Output is correct
26 Correct 74 ms 6820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 81 ms 5348 KB Output is correct
14 Correct 86 ms 5304 KB Output is correct
15 Correct 79 ms 5488 KB Output is correct
16 Correct 81 ms 5936 KB Output is correct
17 Correct 79 ms 5400 KB Output is correct
18 Correct 83 ms 5560 KB Output is correct
19 Correct 76 ms 5816 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 78 ms 5500 KB Output is correct
23 Correct 89 ms 5716 KB Output is correct
24 Correct 216 ms 8256 KB Output is correct
25 Correct 193 ms 6984 KB Output is correct
26 Correct 146 ms 8376 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 78 ms 6784 KB Output is correct
30 Correct 75 ms 6060 KB Output is correct
31 Correct 81 ms 6824 KB Output is correct
32 Correct 75 ms 6068 KB Output is correct
33 Correct 76 ms 5684 KB Output is correct
34 Correct 94 ms 5816 KB Output is correct
35 Correct 74 ms 6820 KB Output is correct
36 Correct 324 ms 8636 KB Output is correct
37 Correct 311 ms 8240 KB Output is correct
38 Correct 290 ms 7096 KB Output is correct
39 Correct 234 ms 7868 KB Output is correct
40 Correct 328 ms 7356 KB Output is correct
41 Correct 358 ms 16952 KB Output is correct
42 Correct 363 ms 18104 KB Output is correct
43 Correct 344 ms 28344 KB Output is correct
44 Correct 362 ms 28220 KB Output is correct
45 Correct 337 ms 7232 KB Output is correct
46 Correct 431 ms 9768 KB Output is correct
47 Correct 359 ms 8752 KB Output is correct
48 Correct 281 ms 7728 KB Output is correct