답안 #833030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833030 2023-08-21T19:57:07 Z Liudas Inspections (NOI23_inspections) C++17
100 / 100
858 ms 43412 KB
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <climits>
#include <algorithm>
#define int long long
using namespace std;
struct seg{
    int l;
    int r;
    int time;
    bool operator<(const seg &a)const{
        if(l == a.l){
            return r < a.r;
        }
        return l < a.l;
    }
};
map<int, int> vals;
set<seg> in;
vector<seg> to_err, to_add;
void compare(seg &a, seg &b){
    if(b.l < a.l){
        seg c = {b.l, a.l-1, b.time};
        to_add.push_back(c);
        b.time += a.l - b.l;
        b.l = a.l;
    }
    if(b.r > a.r){
        seg c = {a.r + 1, b.r, b.time + a.r - b.l + 1};
        to_add.push_back(c);
        b.r = a.r;
    }
}
signed main(){
    int N, Q, M;
    cin >> N >> M >> Q;
    vector<seg> arr(M);
    int day = 0;
    for(int i = 0; i < M; i ++){
        int a, b;
        cin >> a >> b;
        arr[i] = {a,b,day};
        day += b-a+1;
    }
    seg tt = {INT_MIN, INT_MIN, INT_MIN};
    in.insert(tt);
    for(int i = 0; i < M; i ++){
        seg a = arr[i];
        seg t = {a.r, INT_MAX, 0};
        auto p = --in.upper_bound(t);
        while((*p).r >= a.l){
            seg b = *p;
            p--;
            to_err.push_back(b);
            compare(a, b);
            int lmax = max(a.l, b.l);
            int rmin = min(a.r, b.r);
            int td = b.l - a.l;
            vals[a.time + td - b.time - 1] += rmin-lmax+1;
        }
        for(auto j : to_err){
            in.erase(j);
        }
        to_err.clear();
        for(auto j : to_add){
            in.insert(j);
        }
        to_add.clear();
        in.insert(a);
    }
    vector<pair<int, int>> pref;
    for(auto[l, r] : vals){
        pref.push_back({l, r});
    }
    pref.push_back({(int)1e16, 0ll});
    for(int i = (int)pref.size()-2; i > -1; i --){
        pref[i].second += pref[i+1].second;
    }
    for(int i = 0; i < Q; i ++){
        int q;
        cin >> q;
        cout << (*lower_bound(pref.begin(), pref.end(), make_pair(q, 0ll))).second << " ";
    }
    cout << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 263 ms 1056 KB Output is correct
14 Correct 263 ms 732 KB Output is correct
15 Correct 260 ms 1024 KB Output is correct
16 Correct 301 ms 1296 KB Output is correct
17 Correct 260 ms 972 KB Output is correct
18 Correct 297 ms 1036 KB Output is correct
19 Correct 266 ms 1612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 263 ms 972 KB Output is correct
4 Correct 277 ms 1412 KB Output is correct
5 Correct 583 ms 30648 KB Output is correct
6 Correct 578 ms 30648 KB Output is correct
7 Correct 474 ms 20788 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 263 ms 1056 KB Output is correct
14 Correct 263 ms 732 KB Output is correct
15 Correct 260 ms 1024 KB Output is correct
16 Correct 301 ms 1296 KB Output is correct
17 Correct 260 ms 972 KB Output is correct
18 Correct 297 ms 1036 KB Output is correct
19 Correct 266 ms 1612 KB Output is correct
20 Correct 328 ms 2556 KB Output is correct
21 Correct 261 ms 1244 KB Output is correct
22 Correct 270 ms 2300 KB Output is correct
23 Correct 266 ms 1612 KB Output is correct
24 Correct 259 ms 936 KB Output is correct
25 Correct 270 ms 1400 KB Output is correct
26 Correct 297 ms 2800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 263 ms 1056 KB Output is correct
14 Correct 263 ms 732 KB Output is correct
15 Correct 260 ms 1024 KB Output is correct
16 Correct 301 ms 1296 KB Output is correct
17 Correct 260 ms 972 KB Output is correct
18 Correct 297 ms 1036 KB Output is correct
19 Correct 266 ms 1612 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 263 ms 972 KB Output is correct
23 Correct 277 ms 1412 KB Output is correct
24 Correct 583 ms 30648 KB Output is correct
25 Correct 578 ms 30648 KB Output is correct
26 Correct 474 ms 20788 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 328 ms 2556 KB Output is correct
30 Correct 261 ms 1244 KB Output is correct
31 Correct 270 ms 2300 KB Output is correct
32 Correct 266 ms 1612 KB Output is correct
33 Correct 259 ms 936 KB Output is correct
34 Correct 270 ms 1400 KB Output is correct
35 Correct 297 ms 2800 KB Output is correct
36 Correct 644 ms 23380 KB Output is correct
37 Correct 769 ms 36912 KB Output is correct
38 Correct 773 ms 36848 KB Output is correct
39 Correct 411 ms 6176 KB Output is correct
40 Correct 663 ms 33600 KB Output is correct
41 Correct 630 ms 39968 KB Output is correct
42 Correct 614 ms 40876 KB Output is correct
43 Correct 600 ms 43412 KB Output is correct
44 Correct 607 ms 42344 KB Output is correct
45 Correct 813 ms 36980 KB Output is correct
46 Correct 845 ms 34796 KB Output is correct
47 Correct 858 ms 34920 KB Output is correct
48 Correct 740 ms 36792 KB Output is correct