제출 #1117972

#제출 시각아이디문제언어결과실행 시간메모리
1117972blackslexInspections (NOI23_inspections)C++17
100 / 100
687 ms61608 KiB
#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]);
}

컴파일 시 표준 에러 (stderr) 메시지

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 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...