답안 #389814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389814 2021-04-14T14:46:38 Z phathnv 새 집 (APIO18_new_home) C++11
47 / 100
5000 ms 372332 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

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

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){
        if (t != oth.t)
            return t < oth.t;
        return type < oth.type;
    }
};

struct SegmentTree{
    int n, x[N];
    multiset<int> setLeft[N * 4], setRight[N * 4];
    void init(const vector<int> &xCoor){
        n = xCoor.size();
        for(int i = 1; i <= n; i++)
            x[i] = xCoor[i - 1];
    }
    void updateSeg(int id, int l, int r, int u, int v, int val, int type, multiset<int> d[]){
        if (v < x[l] || x[r] < u)
            return;
        if (u <= x[l] && x[r] <= v){
            if (type == -1)
                d[id].erase(d[id].find(val));
            else
                d[id].insert(val);
            return;
        }
        int mid = (l + r) >> 1;
        updateSeg(id << 1, l, mid, u, v, val, type, d);
        updateSeg(id << 1 | 1, mid + 1, r, u, v, val, type, d);
    }
    int getMax(int id, int l, int r, int pos){
        if (pos < x[l] || x[r] < pos)
            return 0;
        int res = 0;
        if (!setLeft[id].empty())
            res = max(res, pos + *(--setLeft[id].end()));
        if (!setRight[id].empty())
            res = max(res, *(--setRight[id].end()) - pos);

        if (l == r)
            return res;
        int mid = (l + r) >> 1;
        res = max(res, getMax(id << 1, l, mid, pos));
        res = max(res, getMax(id << 1 | 1, mid + 1, r, pos));
        return res;
    }
    void updatePair(int l, int r, int type){
        int mid = (l + r) >> 1;
        updateSeg(1, 1, n, l, mid, -l, type, setLeft);
        updateSeg(1, 1, n, mid + 1, r, r, type, setRight);
    }
    int getMax(int pos){
        return getMax(1, 1, n, pos);
    }
} ST;

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

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

    cin >> n >> k >> q;

    for(int i = 1; i <= n; i++){
        int x, t, a, b;
        cin >> x >> t >> a >> b;
        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 x, y;
        cin >> x >> y;
        events.push_back(Event(y, 2, x, i));
        xCoor.push_back(x);
    }

    sort(events.begin(), events.end());
    sort(xCoor.begin(), xCoor.end());
    xCoor.resize(unique(xCoor.begin(), xCoor.end()) - xCoor.begin());
    ST.init(xCoor);

    for(int i = 1; i <= k; i++){
        color[i].insert(-INF);
        color[i].insert(INF);
        ST.updatePair(-INF, INF, 1);
    }
    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.updatePair(l, e.x, -1);
            ST.updatePair(e.x, r, -1);
            ST.updatePair(l, r, 1);
        } else if (e.type == 1){
            auto it = color[e.ind].upper_bound(e.x);
            int r = *it;
            int l = *(--it);
            ST.updatePair(l, r, -1);
            ST.updatePair(l, e.x, 1);
            ST.updatePair(e.x, r, 1);
            color[e.ind].insert(e.x);
        } else {
            answer[e.ind] = ST.getMax(e.x);
        }
    }
    for(int i = 1; i <= q; i++)
        cout << (answer[i] > 1e8? -1 : answer[i]) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 127212 KB Output is correct
2 Correct 78 ms 127072 KB Output is correct
3 Correct 78 ms 127016 KB Output is correct
4 Correct 78 ms 127128 KB Output is correct
5 Correct 78 ms 127108 KB Output is correct
6 Correct 82 ms 127340 KB Output is correct
7 Correct 79 ms 127232 KB Output is correct
8 Correct 81 ms 127304 KB Output is correct
9 Correct 80 ms 127396 KB Output is correct
10 Correct 85 ms 127308 KB Output is correct
11 Correct 80 ms 127152 KB Output is correct
12 Correct 80 ms 127216 KB Output is correct
13 Correct 79 ms 127080 KB Output is correct
14 Correct 81 ms 127120 KB Output is correct
15 Correct 78 ms 127244 KB Output is correct
16 Correct 79 ms 127228 KB Output is correct
17 Correct 82 ms 127208 KB Output is correct
18 Correct 79 ms 127236 KB Output is correct
19 Correct 90 ms 127200 KB Output is correct
20 Correct 78 ms 127212 KB Output is correct
21 Correct 78 ms 127128 KB Output is correct
22 Correct 85 ms 127280 KB Output is correct
23 Correct 82 ms 127276 KB Output is correct
24 Correct 88 ms 127236 KB Output is correct
25 Correct 80 ms 127140 KB Output is correct
26 Correct 81 ms 127172 KB Output is correct
27 Correct 80 ms 127096 KB Output is correct
28 Correct 80 ms 127200 KB Output is correct
29 Correct 86 ms 127156 KB Output is correct
30 Correct 78 ms 127168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 127212 KB Output is correct
2 Correct 78 ms 127072 KB Output is correct
3 Correct 78 ms 127016 KB Output is correct
4 Correct 78 ms 127128 KB Output is correct
5 Correct 78 ms 127108 KB Output is correct
6 Correct 82 ms 127340 KB Output is correct
7 Correct 79 ms 127232 KB Output is correct
8 Correct 81 ms 127304 KB Output is correct
9 Correct 80 ms 127396 KB Output is correct
10 Correct 85 ms 127308 KB Output is correct
11 Correct 80 ms 127152 KB Output is correct
12 Correct 80 ms 127216 KB Output is correct
13 Correct 79 ms 127080 KB Output is correct
14 Correct 81 ms 127120 KB Output is correct
15 Correct 78 ms 127244 KB Output is correct
16 Correct 79 ms 127228 KB Output is correct
17 Correct 82 ms 127208 KB Output is correct
18 Correct 79 ms 127236 KB Output is correct
19 Correct 90 ms 127200 KB Output is correct
20 Correct 78 ms 127212 KB Output is correct
21 Correct 78 ms 127128 KB Output is correct
22 Correct 85 ms 127280 KB Output is correct
23 Correct 82 ms 127276 KB Output is correct
24 Correct 88 ms 127236 KB Output is correct
25 Correct 80 ms 127140 KB Output is correct
26 Correct 81 ms 127172 KB Output is correct
27 Correct 80 ms 127096 KB Output is correct
28 Correct 80 ms 127200 KB Output is correct
29 Correct 86 ms 127156 KB Output is correct
30 Correct 78 ms 127168 KB Output is correct
31 Correct 2826 ms 175136 KB Output is correct
32 Correct 240 ms 133756 KB Output is correct
33 Correct 1014 ms 141532 KB Output is correct
34 Correct 2787 ms 152064 KB Output is correct
35 Correct 2213 ms 166596 KB Output is correct
36 Correct 1034 ms 148760 KB Output is correct
37 Correct 763 ms 135904 KB Output is correct
38 Correct 517 ms 134808 KB Output is correct
39 Correct 469 ms 134068 KB Output is correct
40 Correct 483 ms 134104 KB Output is correct
41 Correct 967 ms 134652 KB Output is correct
42 Correct 1006 ms 134716 KB Output is correct
43 Correct 152 ms 136148 KB Output is correct
44 Correct 902 ms 134700 KB Output is correct
45 Correct 759 ms 134284 KB Output is correct
46 Correct 633 ms 134276 KB Output is correct
47 Correct 396 ms 133788 KB Output is correct
48 Correct 359 ms 133796 KB Output is correct
49 Correct 508 ms 134136 KB Output is correct
50 Correct 687 ms 134184 KB Output is correct
51 Correct 482 ms 134260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5059 ms 372332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5098 ms 303460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 127212 KB Output is correct
2 Correct 78 ms 127072 KB Output is correct
3 Correct 78 ms 127016 KB Output is correct
4 Correct 78 ms 127128 KB Output is correct
5 Correct 78 ms 127108 KB Output is correct
6 Correct 82 ms 127340 KB Output is correct
7 Correct 79 ms 127232 KB Output is correct
8 Correct 81 ms 127304 KB Output is correct
9 Correct 80 ms 127396 KB Output is correct
10 Correct 85 ms 127308 KB Output is correct
11 Correct 80 ms 127152 KB Output is correct
12 Correct 80 ms 127216 KB Output is correct
13 Correct 79 ms 127080 KB Output is correct
14 Correct 81 ms 127120 KB Output is correct
15 Correct 78 ms 127244 KB Output is correct
16 Correct 79 ms 127228 KB Output is correct
17 Correct 82 ms 127208 KB Output is correct
18 Correct 79 ms 127236 KB Output is correct
19 Correct 90 ms 127200 KB Output is correct
20 Correct 78 ms 127212 KB Output is correct
21 Correct 78 ms 127128 KB Output is correct
22 Correct 85 ms 127280 KB Output is correct
23 Correct 82 ms 127276 KB Output is correct
24 Correct 88 ms 127236 KB Output is correct
25 Correct 80 ms 127140 KB Output is correct
26 Correct 81 ms 127172 KB Output is correct
27 Correct 80 ms 127096 KB Output is correct
28 Correct 80 ms 127200 KB Output is correct
29 Correct 86 ms 127156 KB Output is correct
30 Correct 78 ms 127168 KB Output is correct
31 Correct 2826 ms 175136 KB Output is correct
32 Correct 240 ms 133756 KB Output is correct
33 Correct 1014 ms 141532 KB Output is correct
34 Correct 2787 ms 152064 KB Output is correct
35 Correct 2213 ms 166596 KB Output is correct
36 Correct 1034 ms 148760 KB Output is correct
37 Correct 763 ms 135904 KB Output is correct
38 Correct 517 ms 134808 KB Output is correct
39 Correct 469 ms 134068 KB Output is correct
40 Correct 483 ms 134104 KB Output is correct
41 Correct 967 ms 134652 KB Output is correct
42 Correct 1006 ms 134716 KB Output is correct
43 Correct 152 ms 136148 KB Output is correct
44 Correct 902 ms 134700 KB Output is correct
45 Correct 759 ms 134284 KB Output is correct
46 Correct 633 ms 134276 KB Output is correct
47 Correct 396 ms 133788 KB Output is correct
48 Correct 359 ms 133796 KB Output is correct
49 Correct 508 ms 134136 KB Output is correct
50 Correct 687 ms 134184 KB Output is correct
51 Correct 482 ms 134260 KB Output is correct
52 Correct 1194 ms 187184 KB Output is correct
53 Correct 1175 ms 158944 KB Output is correct
54 Correct 2817 ms 196860 KB Output is correct
55 Correct 1284 ms 152432 KB Output is correct
56 Correct 1194 ms 161224 KB Output is correct
57 Correct 1182 ms 140264 KB Output is correct
58 Correct 1370 ms 152596 KB Output is correct
59 Correct 1316 ms 161296 KB Output is correct
60 Correct 1278 ms 140204 KB Output is correct
61 Correct 197 ms 144688 KB Output is correct
62 Correct 1172 ms 187336 KB Output is correct
63 Correct 2059 ms 184372 KB Output is correct
64 Correct 2461 ms 175612 KB Output is correct
65 Correct 2570 ms 148072 KB Output is correct
66 Correct 1084 ms 135488 KB Output is correct
67 Correct 608 ms 136412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 127212 KB Output is correct
2 Correct 78 ms 127072 KB Output is correct
3 Correct 78 ms 127016 KB Output is correct
4 Correct 78 ms 127128 KB Output is correct
5 Correct 78 ms 127108 KB Output is correct
6 Correct 82 ms 127340 KB Output is correct
7 Correct 79 ms 127232 KB Output is correct
8 Correct 81 ms 127304 KB Output is correct
9 Correct 80 ms 127396 KB Output is correct
10 Correct 85 ms 127308 KB Output is correct
11 Correct 80 ms 127152 KB Output is correct
12 Correct 80 ms 127216 KB Output is correct
13 Correct 79 ms 127080 KB Output is correct
14 Correct 81 ms 127120 KB Output is correct
15 Correct 78 ms 127244 KB Output is correct
16 Correct 79 ms 127228 KB Output is correct
17 Correct 82 ms 127208 KB Output is correct
18 Correct 79 ms 127236 KB Output is correct
19 Correct 90 ms 127200 KB Output is correct
20 Correct 78 ms 127212 KB Output is correct
21 Correct 78 ms 127128 KB Output is correct
22 Correct 85 ms 127280 KB Output is correct
23 Correct 82 ms 127276 KB Output is correct
24 Correct 88 ms 127236 KB Output is correct
25 Correct 80 ms 127140 KB Output is correct
26 Correct 81 ms 127172 KB Output is correct
27 Correct 80 ms 127096 KB Output is correct
28 Correct 80 ms 127200 KB Output is correct
29 Correct 86 ms 127156 KB Output is correct
30 Correct 78 ms 127168 KB Output is correct
31 Correct 2826 ms 175136 KB Output is correct
32 Correct 240 ms 133756 KB Output is correct
33 Correct 1014 ms 141532 KB Output is correct
34 Correct 2787 ms 152064 KB Output is correct
35 Correct 2213 ms 166596 KB Output is correct
36 Correct 1034 ms 148760 KB Output is correct
37 Correct 763 ms 135904 KB Output is correct
38 Correct 517 ms 134808 KB Output is correct
39 Correct 469 ms 134068 KB Output is correct
40 Correct 483 ms 134104 KB Output is correct
41 Correct 967 ms 134652 KB Output is correct
42 Correct 1006 ms 134716 KB Output is correct
43 Correct 152 ms 136148 KB Output is correct
44 Correct 902 ms 134700 KB Output is correct
45 Correct 759 ms 134284 KB Output is correct
46 Correct 633 ms 134276 KB Output is correct
47 Correct 396 ms 133788 KB Output is correct
48 Correct 359 ms 133796 KB Output is correct
49 Correct 508 ms 134136 KB Output is correct
50 Correct 687 ms 134184 KB Output is correct
51 Correct 482 ms 134260 KB Output is correct
52 Execution timed out 5059 ms 372332 KB Time limit exceeded
53 Halted 0 ms 0 KB -