Submission #1117971

#TimeUsernameProblemLanguageResultExecution timeMemory
1117971blackslexInspections (NOI23_inspections)C++17
55 / 100
362 ms42212 KiB
#include<bits/stdc++.h>

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

const int N = 2e5 + 5;
int n, m, q;

int main() {
    scanf("%d %d %d", &n, &m, &q);
    vector<pii> c(m);
    multiset<tp> ms;
    vector<ll> cnt(m);
    map<ll, int> mp;
    for (auto &[x, y]: c) scanf("%d %d", &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 = [&] (int idx) {
        return (idx >= 0 ? cnt[idx] : 0);
    };
    auto getpos = [&] (int val, int 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);
            int 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("%d", &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 (stderr)

Main.cpp: In function 'int main()':
Main.cpp:17:35: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'std::tuple_element<0, std::pair<long long int, long long int> >::type*' {aka 'long long int*'} [-Wformat=]
   17 |     for (auto &[x, y]: c) scanf("%d %d", &x, &y);
      |                                  ~^      ~~
      |                                   |      |
      |                                   int*   std::tuple_element<0, std::pair<long long int, long long int> >::type* {aka long long int*}
      |                                  %lld
Main.cpp:17:38: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'std::tuple_element<1, std::pair<long long int, long long int> >::type*' {aka 'long long int*'} [-Wformat=]
   17 |     for (auto &[x, y]: c) scanf("%d %d", &x, &y);
      |                                     ~^       ~~
      |                                      |       |
      |                                      int*    std::tuple_element<1, std::pair<long long int, long long int> >::type* {aka long long int*}
      |                                     %lld
Main.cpp:53:31: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   53 |     for (auto &e: cq) scanf("%d", &e);
      |                              ~^   ~~
      |                               |   |
      |                               |   long long int*
      |                               int*
      |                              %lld
Main.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %d %d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:17:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     for (auto &[x, y]: c) scanf("%d %d", &x, &y);
      |                           ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:53:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     for (auto &e: cq) scanf("%d", &e);
      |                       ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...