제출 #1118211

#제출 시각아이디문제언어결과실행 시간메모리
1118211knot222Inspections (NOI23_inspections)C++14
100 / 100
251 ms38856 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(NULL);
    int N,M,S;cin>>N>>M>>S;
    vector<pair<int,int>> ta(M);
    for (int i=0;i<M;i++) {
        cin>>ta[i].first >> ta[i].second;
    }
    
    priority_queue<pair<ll,ll>> ss;
    vector<ll> ans(S);
    for (int i=0;i<S;i++) {
        ll t1;
        cin>>t1;
        ss.push(make_pair(t1,i));
    }
    priority_queue<pair<ll,ll>> sl;
    //right -> {left, time}
    map<int,pair<int,ll>> range;
    ll tim = 0;
    for (int i=0;i<M;i++) {
        auto it = range.lower_bound(ta[i].first);
        if (it!=range.end()) {
            int l = it->second.first;
            int r = it->first;
            ll tt = it->second.second;
            if (l<ta[i].first) {
                range[ta[i].first-1] = {l, tt-(r-ta[i].first)-1};
                it->second.first = ta[i].first;
            }
        }
        while (it!=range.end() && it->first<=ta[i].second) {
            int l = it->second.first;
            int r = it->first;
            ll tt = it->second.second;
            //sl.push(make_pair(tim-ta[i].first+r-tt, r-l+1));
            sl.push(make_pair(tim-ta[i].first+r-tt, r-l+1));
            it = range.erase(it);
        }
        if (it!=range.end()) {
            int l = it->second.first;
            int r = it->first;
            ll tt = it->second.second;
            if (l<=ta[i].second) {
                sl.push(make_pair(tim-ta[i].first+r-tt, ta[i].second-l+1));
                it->second.first = ta[i].second+1;
            }
        }
        tim+=ta[i].second-ta[i].first+1;
        range[ta[i].second] = make_pair(ta[i].first, tim);
    }
    ll sum=0;
    while (!ss.empty()) {
        while (!ss.empty() && !sl.empty() && ss.top().first<=sl.top().first) {
            sum+=sl.top().second;
            sl.pop();
        }
        ans[ss.top().second] = sum;
        ss.pop();
    }
    for (int i=0;i<S;i++) {
        cout << ans[i] << ' ';
    }
    return 0;
}
/*
5 3 7                                       
1 3
3 5
2 3
0 1 2 3 4 5 6
*/
#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...