Submission #390102

# Submission time Handle Problem Language Result Execution time Memory
390102 2021-04-15T10:38:05 Z phathnv New Home (APIO18_new_home) C++11
100 / 100
4974 ms 103032 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 3e5 + 7;
const int INF = 1e9;

struct Coor{
    int x, t;
    Coor(int _x = 0, int _t = 0){
        x = _x;
        t = _t;
    }
    bool operator < (const Coor &oth) const {
        if (x != oth.x)
            return x < oth.x;
        return t < oth.t;
    }
    bool operator == (const Coor &oth) const {
        return (x == oth.x && t == oth.t);
    }
};

struct Event{
    int t, type, x, ind;
    Event(int _t, int _type, int _x, int _ind){
        t = _t;
        type = _type;
        x = _x;
        ind = _ind;
    }
    bool operator < (const Event &oth) const {
        if (t != oth.t)
            return t < oth.t;
        return type < oth.type;
    }
};

struct SegmentTree{
    int n;
    vector<int> d;
    void init(int _n){
        n = _n;
        d.assign(n * 4 + 1, 0);
    }
    void update(int id, int l, int r, int pos, int val){
        if (pos < l || r < pos)
            return;
        if (l == r){
            d[id] = val;
            return;
        }
        int mid = (l + r) >> 1;
        update(id << 1, l, mid, pos, val);
        update(id << 1 | 1, mid + 1, r, pos, val);
        d[id] = max(d[id << 1], d[id << 1 | 1]);
    }
    int getMax(int id, int l, int r, int u, int v){
        if (v < l || r < u)
            return 0;
        if (u <= l && r <= v)
            return d[id];
        int mid = (l + r) >> 1;
        return max(getMax(id << 1, l, mid, u, v), getMax(id << 1 | 1, mid + 1, r, u, v));
    }

    void update(int pos, int val){
        update(1, 1, n, pos, val);
    }
    int getMax(int l, int r){
        return getMax(1, 1, n, l, r);
    }
} ST;

int n, k, q, answer[N];
vector<Coor> xCoor;
vector<Event> events;
multiset<int> color[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> n >> k >> q;
    for(int i = 1; i <= n; i++){
        int x, t, a, b;
        cin >> x >> t >> a >> b;
        xCoor.push_back(Coor{x, t});
        events.push_back(Event(a, 1, x, t));
        events.push_back(Event(b + 1, -1, x, t));
    }
    for(int i = 1; i <= q; i++){
        int l, y;
        cin >> l >> y;
        events.push_back(Event(y, 2, l, i));
    }
    for(int i = 1; i <= k; i++)
        xCoor.push_back(Coor(-INF, i));
    sort(xCoor.begin(), xCoor.end());
    xCoor.resize(unique(xCoor.begin(), xCoor.end()) - xCoor.begin());
    sort(events.begin(), events.end());
    for(Event &e : events)
        if (e.type != 2)
            e.x = lower_bound(xCoor.begin(), xCoor.end(), Coor(e.x, e.ind)) - xCoor.begin() + 1;

    ST.init(xCoor.size());
    for(int i = 1; i <= k; i++){
        color[i].insert(i);
        color[i].insert(INF);
        ST.update(i, INF);
    }
    for(Event e : events)
        if (e.type == -1){
            color[e.ind].erase(color[e.ind].find(e.x));
            auto it = color[e.ind].upper_bound(e.x);
            int r = *it;
            int l = *(--it);
            ST.update(e.x, 0);
            ST.update(l, r);
        } else if (e.type == 1){
            auto it = color[e.ind].upper_bound(e.x);
            int r = *it;
            int l = *(--it);
            ST.update(l, e.x);
            ST.update(e.x, r);
            color[e.ind].insert(e.x);
        } else {
            int lo = 0, hi = 1e8;
            answer[e.ind] = -1;
            while (lo <= hi){
                int mid = (lo + hi) >> 1;
                int l = lower_bound(xCoor.begin(), xCoor.end(), Coor(e.x - mid, -INF)) - xCoor.begin() + 1;
                int r = upper_bound(xCoor.begin(), xCoor.end(), Coor(e.x + mid, INF)) - xCoor.begin();
                if (ST.getMax(1, l - 1) <= r){
                    answer[e.ind] = mid;
                    hi = mid - 1;
                } else {
                    lo = mid + 1;
                }
            }
        }
    for(int i = 1; i <= q; i++)
        cout << answer[i] << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14412 KB Output is correct
3 Correct 10 ms 14416 KB Output is correct
4 Correct 10 ms 14412 KB Output is correct
5 Correct 11 ms 14476 KB Output is correct
6 Correct 12 ms 14476 KB Output is correct
7 Correct 11 ms 14428 KB Output is correct
8 Correct 12 ms 14412 KB Output is correct
9 Correct 11 ms 14540 KB Output is correct
10 Correct 11 ms 14412 KB Output is correct
11 Correct 11 ms 14548 KB Output is correct
12 Correct 12 ms 14376 KB Output is correct
13 Correct 11 ms 14412 KB Output is correct
14 Correct 11 ms 14492 KB Output is correct
15 Correct 11 ms 14420 KB Output is correct
16 Correct 11 ms 14412 KB Output is correct
17 Correct 11 ms 14412 KB Output is correct
18 Correct 11 ms 14480 KB Output is correct
19 Correct 11 ms 14412 KB Output is correct
20 Correct 11 ms 14412 KB Output is correct
21 Correct 11 ms 14524 KB Output is correct
22 Correct 11 ms 14416 KB Output is correct
23 Correct 11 ms 14412 KB Output is correct
24 Correct 11 ms 14412 KB Output is correct
25 Correct 12 ms 14424 KB Output is correct
26 Correct 11 ms 14412 KB Output is correct
27 Correct 11 ms 14412 KB Output is correct
28 Correct 11 ms 14468 KB Output is correct
29 Correct 11 ms 14412 KB Output is correct
30 Correct 11 ms 14476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14412 KB Output is correct
3 Correct 10 ms 14416 KB Output is correct
4 Correct 10 ms 14412 KB Output is correct
5 Correct 11 ms 14476 KB Output is correct
6 Correct 12 ms 14476 KB Output is correct
7 Correct 11 ms 14428 KB Output is correct
8 Correct 12 ms 14412 KB Output is correct
9 Correct 11 ms 14540 KB Output is correct
10 Correct 11 ms 14412 KB Output is correct
11 Correct 11 ms 14548 KB Output is correct
12 Correct 12 ms 14376 KB Output is correct
13 Correct 11 ms 14412 KB Output is correct
14 Correct 11 ms 14492 KB Output is correct
15 Correct 11 ms 14420 KB Output is correct
16 Correct 11 ms 14412 KB Output is correct
17 Correct 11 ms 14412 KB Output is correct
18 Correct 11 ms 14480 KB Output is correct
19 Correct 11 ms 14412 KB Output is correct
20 Correct 11 ms 14412 KB Output is correct
21 Correct 11 ms 14524 KB Output is correct
22 Correct 11 ms 14416 KB Output is correct
23 Correct 11 ms 14412 KB Output is correct
24 Correct 11 ms 14412 KB Output is correct
25 Correct 12 ms 14424 KB Output is correct
26 Correct 11 ms 14412 KB Output is correct
27 Correct 11 ms 14412 KB Output is correct
28 Correct 11 ms 14468 KB Output is correct
29 Correct 11 ms 14412 KB Output is correct
30 Correct 11 ms 14476 KB Output is correct
31 Correct 710 ms 23072 KB Output is correct
32 Correct 183 ms 20280 KB Output is correct
33 Correct 687 ms 21168 KB Output is correct
34 Correct 630 ms 21268 KB Output is correct
35 Correct 661 ms 22956 KB Output is correct
36 Correct 695 ms 22904 KB Output is correct
37 Correct 614 ms 20708 KB Output is correct
38 Correct 621 ms 20536 KB Output is correct
39 Correct 560 ms 20700 KB Output is correct
40 Correct 581 ms 20636 KB Output is correct
41 Correct 476 ms 20684 KB Output is correct
42 Correct 422 ms 20528 KB Output is correct
43 Correct 157 ms 22172 KB Output is correct
44 Correct 496 ms 20896 KB Output is correct
45 Correct 485 ms 20792 KB Output is correct
46 Correct 584 ms 20772 KB Output is correct
47 Correct 445 ms 20396 KB Output is correct
48 Correct 459 ms 20396 KB Output is correct
49 Correct 481 ms 20400 KB Output is correct
50 Correct 460 ms 20456 KB Output is correct
51 Correct 500 ms 20680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2826 ms 60996 KB Output is correct
2 Correct 4445 ms 52728 KB Output is correct
3 Correct 2393 ms 89308 KB Output is correct
4 Correct 2451 ms 65948 KB Output is correct
5 Correct 4385 ms 52404 KB Output is correct
6 Correct 4436 ms 52872 KB Output is correct
7 Correct 2283 ms 89400 KB Output is correct
8 Correct 2690 ms 65764 KB Output is correct
9 Correct 3046 ms 57612 KB Output is correct
10 Correct 4104 ms 53536 KB Output is correct
11 Correct 3222 ms 52492 KB Output is correct
12 Correct 3379 ms 53440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3941 ms 54320 KB Output is correct
2 Correct 1045 ms 47172 KB Output is correct
3 Correct 4887 ms 52804 KB Output is correct
4 Correct 2067 ms 87516 KB Output is correct
5 Correct 2746 ms 59336 KB Output is correct
6 Correct 2041 ms 64100 KB Output is correct
7 Correct 4848 ms 52592 KB Output is correct
8 Correct 4816 ms 53036 KB Output is correct
9 Correct 2176 ms 88520 KB Output is correct
10 Correct 2860 ms 62216 KB Output is correct
11 Correct 3273 ms 55544 KB Output is correct
12 Correct 4489 ms 53404 KB Output is correct
13 Correct 3051 ms 51692 KB Output is correct
14 Correct 3031 ms 51168 KB Output is correct
15 Correct 3319 ms 52296 KB Output is correct
16 Correct 3527 ms 52952 KB Output is correct
17 Correct 3643 ms 51916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14412 KB Output is correct
3 Correct 10 ms 14416 KB Output is correct
4 Correct 10 ms 14412 KB Output is correct
5 Correct 11 ms 14476 KB Output is correct
6 Correct 12 ms 14476 KB Output is correct
7 Correct 11 ms 14428 KB Output is correct
8 Correct 12 ms 14412 KB Output is correct
9 Correct 11 ms 14540 KB Output is correct
10 Correct 11 ms 14412 KB Output is correct
11 Correct 11 ms 14548 KB Output is correct
12 Correct 12 ms 14376 KB Output is correct
13 Correct 11 ms 14412 KB Output is correct
14 Correct 11 ms 14492 KB Output is correct
15 Correct 11 ms 14420 KB Output is correct
16 Correct 11 ms 14412 KB Output is correct
17 Correct 11 ms 14412 KB Output is correct
18 Correct 11 ms 14480 KB Output is correct
19 Correct 11 ms 14412 KB Output is correct
20 Correct 11 ms 14412 KB Output is correct
21 Correct 11 ms 14524 KB Output is correct
22 Correct 11 ms 14416 KB Output is correct
23 Correct 11 ms 14412 KB Output is correct
24 Correct 11 ms 14412 KB Output is correct
25 Correct 12 ms 14424 KB Output is correct
26 Correct 11 ms 14412 KB Output is correct
27 Correct 11 ms 14412 KB Output is correct
28 Correct 11 ms 14468 KB Output is correct
29 Correct 11 ms 14412 KB Output is correct
30 Correct 11 ms 14476 KB Output is correct
31 Correct 710 ms 23072 KB Output is correct
32 Correct 183 ms 20280 KB Output is correct
33 Correct 687 ms 21168 KB Output is correct
34 Correct 630 ms 21268 KB Output is correct
35 Correct 661 ms 22956 KB Output is correct
36 Correct 695 ms 22904 KB Output is correct
37 Correct 614 ms 20708 KB Output is correct
38 Correct 621 ms 20536 KB Output is correct
39 Correct 560 ms 20700 KB Output is correct
40 Correct 581 ms 20636 KB Output is correct
41 Correct 476 ms 20684 KB Output is correct
42 Correct 422 ms 20528 KB Output is correct
43 Correct 157 ms 22172 KB Output is correct
44 Correct 496 ms 20896 KB Output is correct
45 Correct 485 ms 20792 KB Output is correct
46 Correct 584 ms 20772 KB Output is correct
47 Correct 445 ms 20396 KB Output is correct
48 Correct 459 ms 20396 KB Output is correct
49 Correct 481 ms 20400 KB Output is correct
50 Correct 460 ms 20456 KB Output is correct
51 Correct 500 ms 20680 KB Output is correct
52 Correct 342 ms 29780 KB Output is correct
53 Correct 345 ms 27988 KB Output is correct
54 Correct 339 ms 25076 KB Output is correct
55 Correct 489 ms 23580 KB Output is correct
56 Correct 497 ms 25260 KB Output is correct
57 Correct 478 ms 21480 KB Output is correct
58 Correct 457 ms 23592 KB Output is correct
59 Correct 474 ms 25132 KB Output is correct
60 Correct 435 ms 21336 KB Output is correct
61 Correct 238 ms 30148 KB Output is correct
62 Correct 365 ms 29808 KB Output is correct
63 Correct 459 ms 25896 KB Output is correct
64 Correct 460 ms 24248 KB Output is correct
65 Correct 448 ms 21576 KB Output is correct
66 Correct 460 ms 20780 KB Output is correct
67 Correct 362 ms 20848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14412 KB Output is correct
3 Correct 10 ms 14416 KB Output is correct
4 Correct 10 ms 14412 KB Output is correct
5 Correct 11 ms 14476 KB Output is correct
6 Correct 12 ms 14476 KB Output is correct
7 Correct 11 ms 14428 KB Output is correct
8 Correct 12 ms 14412 KB Output is correct
9 Correct 11 ms 14540 KB Output is correct
10 Correct 11 ms 14412 KB Output is correct
11 Correct 11 ms 14548 KB Output is correct
12 Correct 12 ms 14376 KB Output is correct
13 Correct 11 ms 14412 KB Output is correct
14 Correct 11 ms 14492 KB Output is correct
15 Correct 11 ms 14420 KB Output is correct
16 Correct 11 ms 14412 KB Output is correct
17 Correct 11 ms 14412 KB Output is correct
18 Correct 11 ms 14480 KB Output is correct
19 Correct 11 ms 14412 KB Output is correct
20 Correct 11 ms 14412 KB Output is correct
21 Correct 11 ms 14524 KB Output is correct
22 Correct 11 ms 14416 KB Output is correct
23 Correct 11 ms 14412 KB Output is correct
24 Correct 11 ms 14412 KB Output is correct
25 Correct 12 ms 14424 KB Output is correct
26 Correct 11 ms 14412 KB Output is correct
27 Correct 11 ms 14412 KB Output is correct
28 Correct 11 ms 14468 KB Output is correct
29 Correct 11 ms 14412 KB Output is correct
30 Correct 11 ms 14476 KB Output is correct
31 Correct 710 ms 23072 KB Output is correct
32 Correct 183 ms 20280 KB Output is correct
33 Correct 687 ms 21168 KB Output is correct
34 Correct 630 ms 21268 KB Output is correct
35 Correct 661 ms 22956 KB Output is correct
36 Correct 695 ms 22904 KB Output is correct
37 Correct 614 ms 20708 KB Output is correct
38 Correct 621 ms 20536 KB Output is correct
39 Correct 560 ms 20700 KB Output is correct
40 Correct 581 ms 20636 KB Output is correct
41 Correct 476 ms 20684 KB Output is correct
42 Correct 422 ms 20528 KB Output is correct
43 Correct 157 ms 22172 KB Output is correct
44 Correct 496 ms 20896 KB Output is correct
45 Correct 485 ms 20792 KB Output is correct
46 Correct 584 ms 20772 KB Output is correct
47 Correct 445 ms 20396 KB Output is correct
48 Correct 459 ms 20396 KB Output is correct
49 Correct 481 ms 20400 KB Output is correct
50 Correct 460 ms 20456 KB Output is correct
51 Correct 500 ms 20680 KB Output is correct
52 Correct 2826 ms 60996 KB Output is correct
53 Correct 4445 ms 52728 KB Output is correct
54 Correct 2393 ms 89308 KB Output is correct
55 Correct 2451 ms 65948 KB Output is correct
56 Correct 4385 ms 52404 KB Output is correct
57 Correct 4436 ms 52872 KB Output is correct
58 Correct 2283 ms 89400 KB Output is correct
59 Correct 2690 ms 65764 KB Output is correct
60 Correct 3046 ms 57612 KB Output is correct
61 Correct 4104 ms 53536 KB Output is correct
62 Correct 3222 ms 52492 KB Output is correct
63 Correct 3379 ms 53440 KB Output is correct
64 Correct 3941 ms 54320 KB Output is correct
65 Correct 1045 ms 47172 KB Output is correct
66 Correct 4887 ms 52804 KB Output is correct
67 Correct 2067 ms 87516 KB Output is correct
68 Correct 2746 ms 59336 KB Output is correct
69 Correct 2041 ms 64100 KB Output is correct
70 Correct 4848 ms 52592 KB Output is correct
71 Correct 4816 ms 53036 KB Output is correct
72 Correct 2176 ms 88520 KB Output is correct
73 Correct 2860 ms 62216 KB Output is correct
74 Correct 3273 ms 55544 KB Output is correct
75 Correct 4489 ms 53404 KB Output is correct
76 Correct 3051 ms 51692 KB Output is correct
77 Correct 3031 ms 51168 KB Output is correct
78 Correct 3319 ms 52296 KB Output is correct
79 Correct 3527 ms 52952 KB Output is correct
80 Correct 3643 ms 51916 KB Output is correct
81 Correct 342 ms 29780 KB Output is correct
82 Correct 345 ms 27988 KB Output is correct
83 Correct 339 ms 25076 KB Output is correct
84 Correct 489 ms 23580 KB Output is correct
85 Correct 497 ms 25260 KB Output is correct
86 Correct 478 ms 21480 KB Output is correct
87 Correct 457 ms 23592 KB Output is correct
88 Correct 474 ms 25132 KB Output is correct
89 Correct 435 ms 21336 KB Output is correct
90 Correct 238 ms 30148 KB Output is correct
91 Correct 365 ms 29808 KB Output is correct
92 Correct 459 ms 25896 KB Output is correct
93 Correct 460 ms 24248 KB Output is correct
94 Correct 448 ms 21576 KB Output is correct
95 Correct 460 ms 20780 KB Output is correct
96 Correct 362 ms 20848 KB Output is correct
97 Correct 2147 ms 102584 KB Output is correct
98 Correct 920 ms 43184 KB Output is correct
99 Correct 4723 ms 57936 KB Output is correct
100 Correct 2128 ms 93848 KB Output is correct
101 Correct 2146 ms 78824 KB Output is correct
102 Correct 4974 ms 66792 KB Output is correct
103 Correct 3947 ms 57104 KB Output is correct
104 Correct 3987 ms 56532 KB Output is correct
105 Correct 3465 ms 56656 KB Output is correct
106 Correct 3585 ms 56592 KB Output is correct
107 Correct 2928 ms 71312 KB Output is correct
108 Correct 2916 ms 79408 KB Output is correct
109 Correct 2880 ms 59792 KB Output is correct
110 Correct 2726 ms 70860 KB Output is correct
111 Correct 2774 ms 78848 KB Output is correct
112 Correct 2615 ms 59188 KB Output is correct
113 Correct 1289 ms 101316 KB Output is correct
114 Correct 2303 ms 103032 KB Output is correct
115 Correct 2983 ms 83036 KB Output is correct
116 Correct 2940 ms 74928 KB Output is correct
117 Correct 2947 ms 61408 KB Output is correct
118 Correct 2790 ms 58532 KB Output is correct
119 Correct 2344 ms 50324 KB Output is correct
120 Correct 2435 ms 54132 KB Output is correct
121 Correct 2776 ms 55656 KB Output is correct
122 Correct 2865 ms 55592 KB Output is correct
123 Correct 2859 ms 56304 KB Output is correct
124 Correct 2762 ms 57120 KB Output is correct
125 Correct 3174 ms 56732 KB Output is correct
126 Correct 2617 ms 57228 KB Output is correct