Submission #1114769

# Submission time Handle Problem Language Result Execution time Memory
1114769 2024-11-19T14:50:57 Z ttamx Inspections (NOI23_inspections) C++17
100 / 100
226 ms 39484 KB
#include<bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int n,m,q;
    cin >> n >> m >> q;
    vector<int> l(m),r(m);
    vector<int> cnt(n+2);
    for(int i=0;i<m;i++){
        cin >> l[i] >> r[i];
        cnt[l[i]]++;
        cnt[r[i]+1]--;
    }
    vector<pair<ll,int>> qrs;
    vector<ll> ans(q);
    for(int i=0;i<q;i++){
        ll s;
        cin >> s;
        qrs.emplace_back(s,i);
    }
    sort(qrs.rbegin(),qrs.rend());
    vector<pair<ll,int>> a;
    map<int,pair<int,ll>> mp;
    ll t=0;
    for(int i=0;i<m;i++){
        auto it=mp.lower_bound(l[i]);
        if(it!=mp.end()){
            int &pl=it->second.first;
            int pr=it->first;
            ll pt=it->second.second;
            if(pl<l[i]){
                mp[l[i]-1]={pl,pt-pr+l[i]-1};
                pl=l[i];
            }
        }
        for(;it!=mp.end()&&it->first<=r[i];it=mp.erase(it)){
            int cl=it->second.first;
            int cr=it->first;
            ll pt=it->second.second;
            a.emplace_back(t+cr-l[i]-pt,cr-cl+1);
        }
        if(it!=mp.end()){
            int &pl=it->second.first;
            int pr=it->first;
            ll pt=it->second.second;
            if(pl<=r[i]){
                a.emplace_back(t+pr-l[i]-pt,r[i]-pl+1);
                pl=r[i]+1;
            }
        }
        t+=r[i]-l[i]+1;
        mp[r[i]]={l[i],t};
    }
    a.emplace_back(-1,0);
    sort(a.begin(),a.end());
    ll base=0;
    for(auto [s,i]:qrs){
        while(a.back().first>=s){
            base+=a.back().second;
            a.pop_back();
        }
        ans[i]=base;
    }
    for(auto x:ans){
        cout << x << " ";
    }
}
# 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 336 KB Output is correct
5 Correct 1 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 1 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 336 KB Output is correct
5 Correct 1 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 1 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 41 ms 9412 KB Output is correct
14 Correct 39 ms 9412 KB Output is correct
15 Correct 41 ms 9292 KB Output is correct
16 Correct 40 ms 9412 KB Output is correct
17 Correct 39 ms 9424 KB Output is correct
18 Correct 40 ms 9412 KB Output is correct
19 Correct 41 ms 9156 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 41 ms 8132 KB Output is correct
4 Correct 45 ms 8912 KB Output is correct
5 Correct 110 ms 18676 KB Output is correct
6 Correct 113 ms 22980 KB Output is correct
7 Correct 91 ms 18184 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 336 KB Output is correct
5 Correct 1 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 1 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 41 ms 9412 KB Output is correct
14 Correct 39 ms 9412 KB Output is correct
15 Correct 41 ms 9292 KB Output is correct
16 Correct 40 ms 9412 KB Output is correct
17 Correct 39 ms 9424 KB Output is correct
18 Correct 40 ms 9412 KB Output is correct
19 Correct 41 ms 9156 KB Output is correct
20 Correct 44 ms 10180 KB Output is correct
21 Correct 48 ms 10180 KB Output is correct
22 Correct 45 ms 10180 KB Output is correct
23 Correct 42 ms 10180 KB Output is correct
24 Correct 40 ms 10180 KB Output is correct
25 Correct 56 ms 10448 KB Output is correct
26 Correct 45 ms 10168 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 336 KB Output is correct
5 Correct 1 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 1 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 41 ms 9412 KB Output is correct
14 Correct 39 ms 9412 KB Output is correct
15 Correct 41 ms 9292 KB Output is correct
16 Correct 40 ms 9412 KB Output is correct
17 Correct 39 ms 9424 KB Output is correct
18 Correct 40 ms 9412 KB Output is correct
19 Correct 41 ms 9156 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 41 ms 8132 KB Output is correct
23 Correct 45 ms 8912 KB Output is correct
24 Correct 110 ms 18676 KB Output is correct
25 Correct 113 ms 22980 KB Output is correct
26 Correct 91 ms 18184 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 44 ms 10180 KB Output is correct
30 Correct 48 ms 10180 KB Output is correct
31 Correct 45 ms 10180 KB Output is correct
32 Correct 42 ms 10180 KB Output is correct
33 Correct 40 ms 10180 KB Output is correct
34 Correct 56 ms 10448 KB Output is correct
35 Correct 45 ms 10168 KB Output is correct
36 Correct 161 ms 29836 KB Output is correct
37 Correct 160 ms 31036 KB Output is correct
38 Correct 158 ms 32060 KB Output is correct
39 Correct 124 ms 26808 KB Output is correct
40 Correct 156 ms 31940 KB Output is correct
41 Correct 187 ms 37088 KB Output is correct
42 Correct 175 ms 39484 KB Output is correct
43 Correct 214 ms 34512 KB Output is correct
44 Correct 210 ms 34484 KB Output is correct
45 Correct 175 ms 31288 KB Output is correct
46 Correct 226 ms 27320 KB Output is correct
47 Correct 197 ms 28604 KB Output is correct
48 Correct 148 ms 31544 KB Output is correct