답안 #882714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882714 2023-12-03T13:49:31 Z tsumondai Inspections (NOI23_inspections) C++14
100 / 100
681 ms 49848 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int MAXN = 1e6 + 5;

const int oo = 1e9, mod = 1e9 + 7;

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;
    }
}

void process() {
    int N, Q, M;
    cin >> N >> M >> Q;
    vector<seg> arr(M);
    int day = 0;
    foru(i, 0, M - 1) {
        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);
    foru(i, 0, M - 1) {
        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 tmp : vals) {
        int l = tmp.fi, r = tmp.se;
        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;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    process();
    cerr << "Time elapsed: " << __TIME << " s.\n";
    return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 704 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 704 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 31 ms 2652 KB Output is correct
14 Correct 27 ms 2136 KB Output is correct
15 Correct 29 ms 2632 KB Output is correct
16 Correct 35 ms 2896 KB Output is correct
17 Correct 31 ms 2672 KB Output is correct
18 Correct 29 ms 2648 KB Output is correct
19 Correct 67 ms 2892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 30 ms 2640 KB Output is correct
4 Correct 46 ms 3604 KB Output is correct
5 Correct 343 ms 33028 KB Output is correct
6 Correct 329 ms 33312 KB Output is correct
7 Correct 248 ms 23368 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 704 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 31 ms 2652 KB Output is correct
14 Correct 27 ms 2136 KB Output is correct
15 Correct 29 ms 2632 KB Output is correct
16 Correct 35 ms 2896 KB Output is correct
17 Correct 31 ms 2672 KB Output is correct
18 Correct 29 ms 2648 KB Output is correct
19 Correct 67 ms 2892 KB Output is correct
20 Correct 41 ms 4064 KB Output is correct
21 Correct 35 ms 2860 KB Output is correct
22 Correct 42 ms 3872 KB Output is correct
23 Correct 33 ms 2896 KB Output is correct
24 Correct 29 ms 2404 KB Output is correct
25 Correct 67 ms 3324 KB Output is correct
26 Correct 41 ms 3920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 704 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 31 ms 2652 KB Output is correct
14 Correct 27 ms 2136 KB Output is correct
15 Correct 29 ms 2632 KB Output is correct
16 Correct 35 ms 2896 KB Output is correct
17 Correct 31 ms 2672 KB Output is correct
18 Correct 29 ms 2648 KB Output is correct
19 Correct 67 ms 2892 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 30 ms 2640 KB Output is correct
23 Correct 46 ms 3604 KB Output is correct
24 Correct 343 ms 33028 KB Output is correct
25 Correct 329 ms 33312 KB Output is correct
26 Correct 248 ms 23368 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 408 KB Output is correct
29 Correct 41 ms 4064 KB Output is correct
30 Correct 35 ms 2860 KB Output is correct
31 Correct 42 ms 3872 KB Output is correct
32 Correct 33 ms 2896 KB Output is correct
33 Correct 29 ms 2404 KB Output is correct
34 Correct 67 ms 3324 KB Output is correct
35 Correct 41 ms 3920 KB Output is correct
36 Correct 500 ms 27632 KB Output is correct
37 Correct 617 ms 41000 KB Output is correct
38 Correct 564 ms 41844 KB Output is correct
39 Correct 119 ms 10308 KB Output is correct
40 Correct 339 ms 37988 KB Output is correct
41 Correct 315 ms 43516 KB Output is correct
42 Correct 364 ms 44764 KB Output is correct
43 Correct 342 ms 49848 KB Output is correct
44 Correct 338 ms 47556 KB Output is correct
45 Correct 681 ms 40956 KB Output is correct
46 Correct 625 ms 38216 KB Output is correct
47 Correct 586 ms 38528 KB Output is correct
48 Correct 512 ms 41536 KB Output is correct