Submission #833025

# Submission time Handle Problem Language Result Execution time Memory
833025 2023-08-21T19:43:57 Z Liudas Inspections (NOI23_inspections) C++17
77 / 100
2000 ms 36892 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;
    }
};
// need : inter left 
// got : cover all inter right

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;
    }
    for(int i = 0; i < M; i ++){
        seg a = arr[i];
        seg t = a;
        t.r = INT_MIN;
        auto p = in.begin();
        while(p != in.end() && (*p).l <= a.r){
            if((*p).r < a.l){p++;continue;}
            seg b = *p;
            p++;
            //cout << " A   " << a.l << " " << a.r << " " << a.time << endl;
            //cout << " B   " << b.l << " " << b.r << " " << b.time << endl;
            to_err.push_back(b);
            compare(a, b);
            //cout << "AD A   " << a.l << " " << a.r << " " << a.time << endl;
            //cout << "AD B   " << b.l << " " << b.r << " " << b.time << endl;
            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);
    }
    for(auto i : in){
        //cout << "liko " << i.l << " " << i.r << " " << i.time << endl;
    }
    vector<pair<int, int>> pref;
    for(auto[l, r] : vals){
        pref.push_back({l, r});
        //cout << l <<" " << r << endl;
    }
    pref.push_back({(int)1e16, 0ll});
    for(int i = (int)pref.size()-2; i > -1; i --){
        pref[i].second += pref[i+1].second;
    }
    for(auto[l, r] : pref){
       //cout << "P   " << l << " " << r << endl;
    }
    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;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:52:13: warning: variable 't' set but not used [-Wunused-but-set-variable]
   52 |         seg t = a;
      |             ^
Main.cpp:80:14: warning: variable 'i' set but not used [-Wunused-but-set-variable]
   80 |     for(auto i : in){
      |              ^
Main.cpp:92:13: warning: structured binding declaration set but not used [-Wunused-but-set-variable]
   92 |     for(auto[l, r] : pref){
      |             ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 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 224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 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 224 KB Output is correct
13 Correct 262 ms 1140 KB Output is correct
14 Correct 256 ms 632 KB Output is correct
15 Correct 259 ms 1040 KB Output is correct
16 Correct 278 ms 1236 KB Output is correct
17 Correct 257 ms 1004 KB Output is correct
18 Correct 262 ms 972 KB Output is correct
19 Correct 267 ms 1504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 261 ms 1080 KB Output is correct
4 Correct 273 ms 1424 KB Output is correct
5 Correct 543 ms 30708 KB Output is correct
6 Correct 548 ms 30608 KB Output is correct
7 Correct 437 ms 20788 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 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 224 KB Output is correct
13 Correct 262 ms 1140 KB Output is correct
14 Correct 256 ms 632 KB Output is correct
15 Correct 259 ms 1040 KB Output is correct
16 Correct 278 ms 1236 KB Output is correct
17 Correct 257 ms 1004 KB Output is correct
18 Correct 262 ms 972 KB Output is correct
19 Correct 267 ms 1504 KB Output is correct
20 Correct 272 ms 2504 KB Output is correct
21 Correct 260 ms 1304 KB Output is correct
22 Correct 271 ms 2376 KB Output is correct
23 Correct 274 ms 1420 KB Output is correct
24 Correct 264 ms 972 KB Output is correct
25 Correct 289 ms 1356 KB Output is correct
26 Correct 269 ms 2820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 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 224 KB Output is correct
13 Correct 262 ms 1140 KB Output is correct
14 Correct 256 ms 632 KB Output is correct
15 Correct 259 ms 1040 KB Output is correct
16 Correct 278 ms 1236 KB Output is correct
17 Correct 257 ms 1004 KB Output is correct
18 Correct 262 ms 972 KB Output is correct
19 Correct 267 ms 1504 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 261 ms 1080 KB Output is correct
23 Correct 273 ms 1424 KB Output is correct
24 Correct 543 ms 30708 KB Output is correct
25 Correct 548 ms 30608 KB Output is correct
26 Correct 437 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 272 ms 2504 KB Output is correct
30 Correct 260 ms 1304 KB Output is correct
31 Correct 271 ms 2376 KB Output is correct
32 Correct 274 ms 1420 KB Output is correct
33 Correct 264 ms 972 KB Output is correct
34 Correct 289 ms 1356 KB Output is correct
35 Correct 269 ms 2820 KB Output is correct
36 Correct 601 ms 23288 KB Output is correct
37 Correct 745 ms 36892 KB Output is correct
38 Correct 745 ms 36840 KB Output is correct
39 Correct 1586 ms 6264 KB Output is correct
40 Correct 1265 ms 33684 KB Output is correct
41 Execution timed out 2071 ms 9860 KB Time limit exceeded
42 Halted 0 ms 0 KB -