Submission #1117972

# Submission time Handle Problem Language Result Execution time Memory
1117972 2024-11-24T14:12:21 Z blackslex Inspections (NOI23_inspections) C++17
100 / 100
687 ms 61608 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

ll n, m, q;

int main() {
    scanf("%lld %lld %lld", &n, &m, &q);
    vector<pii> c(m);
    multiset<tp> ms;
    vector<ll> cnt(m);
    map<ll, ll> mp;
    for (auto &[x, y]: c) scanf("%lld %lld", &x, &y);
    for (int i = 0; i < m; i++) {
        cnt[i] = c[i].second - c[i].first + 1;
        if (i) cnt[i] += cnt[i - 1];
    }
    auto get2 = [&] (ll idx) {
        return (idx >= 0 ? cnt[idx] : 0);
    };
    auto getpos = [&] (ll val, ll idx) {
        auto [x, y] = c[idx];
        ll pos = get2(idx - 1) + val - x + 1;
        return pos;
    };
    for (int i = 0; i < m; i++) {
        auto [l, r] = c[i];
        auto it = ms.lower_bound(tp(l, 0, 0));
        if (it != ms.begin() && get<1>(*prev(it)) >= l) it = prev(it);
        vector<tp> cc, cc2;
        while (it != ms.end() && get<0>(*it) <= r) {
            auto [x, y, z] = *it;
            cc.emplace_back(*it);
            ll diff = getpos(x, i) - getpos(x, z);
            ll sz = y - x + 1;
            if (x < l) sz -= l - x;
            if (y > r) sz -= y - r;
            mp[diff] += sz;
            if (x < l) cc2.emplace_back(x, l - 1, z);
            if (y > r) cc2.emplace_back(r + 1, y, z);
            it = next(it);
        }
        for (auto &e: cc) ms.erase(ms.find(e));
        for (auto &e: cc2) ms.emplace(e);
        ms.emplace(l, r, i);
    }
    vector<ll> cq(q), ans(q);
    vector<tp> co;
    for (auto &e: cq) scanf("%lld", &e);
    for (int i = 0; i < q; i++) co.emplace_back(cq[i], 0, i);
    for (auto &[x, y]: mp) co.emplace_back(x - 1, 1, y);
    sort(co.rbegin(), co.rend());
    ll cans = 0;
    for (auto &[x, y, z]: co) {
        if (y) cans += z;
        else ans[z] = cans;
    }
    for (int i = 0; i < q; i++) printf("%lld ", ans[i]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%lld %lld %lld", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:16:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     for (auto &[x, y]: c) scanf("%lld %lld", &x, &y);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:52:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     for (auto &e: cq) scanf("%lld", &e);
      |                       ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 50 ms 9920 KB Output is correct
14 Correct 50 ms 9660 KB Output is correct
15 Correct 51 ms 10944 KB Output is correct
16 Correct 55 ms 11144 KB Output is correct
17 Correct 49 ms 9932 KB Output is correct
18 Correct 52 ms 10936 KB Output is correct
19 Correct 51 ms 9920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 508 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 49 ms 9912 KB Output is correct
4 Correct 64 ms 9920 KB Output is correct
5 Correct 368 ms 38632 KB Output is correct
6 Correct 411 ms 37848 KB Output is correct
7 Correct 234 ms 33200 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 50 ms 9920 KB Output is correct
14 Correct 50 ms 9660 KB Output is correct
15 Correct 51 ms 10944 KB Output is correct
16 Correct 55 ms 11144 KB Output is correct
17 Correct 49 ms 9932 KB Output is correct
18 Correct 52 ms 10936 KB Output is correct
19 Correct 51 ms 9920 KB Output is correct
20 Correct 53 ms 10468 KB Output is correct
21 Correct 51 ms 10948 KB Output is correct
22 Correct 51 ms 11444 KB Output is correct
23 Correct 48 ms 10172 KB Output is correct
24 Correct 48 ms 9924 KB Output is correct
25 Correct 51 ms 9912 KB Output is correct
26 Correct 56 ms 10668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 50 ms 9920 KB Output is correct
14 Correct 50 ms 9660 KB Output is correct
15 Correct 51 ms 10944 KB Output is correct
16 Correct 55 ms 11144 KB Output is correct
17 Correct 49 ms 9932 KB Output is correct
18 Correct 52 ms 10936 KB Output is correct
19 Correct 51 ms 9920 KB Output is correct
20 Correct 1 ms 508 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 49 ms 9912 KB Output is correct
23 Correct 64 ms 9920 KB Output is correct
24 Correct 368 ms 38632 KB Output is correct
25 Correct 411 ms 37848 KB Output is correct
26 Correct 234 ms 33200 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 53 ms 10468 KB Output is correct
30 Correct 51 ms 10948 KB Output is correct
31 Correct 51 ms 11444 KB Output is correct
32 Correct 48 ms 10172 KB Output is correct
33 Correct 48 ms 9924 KB Output is correct
34 Correct 51 ms 9912 KB Output is correct
35 Correct 56 ms 10668 KB Output is correct
36 Correct 399 ms 36996 KB Output is correct
37 Correct 514 ms 60564 KB Output is correct
38 Correct 525 ms 61608 KB Output is correct
39 Correct 140 ms 18592 KB Output is correct
40 Correct 458 ms 45940 KB Output is correct
41 Correct 411 ms 54472 KB Output is correct
42 Correct 375 ms 54896 KB Output is correct
43 Correct 364 ms 55752 KB Output is correct
44 Correct 379 ms 56716 KB Output is correct
45 Correct 550 ms 60788 KB Output is correct
46 Correct 637 ms 46896 KB Output is correct
47 Correct 687 ms 47204 KB Output is correct
48 Correct 569 ms 61076 KB Output is correct