Submission #389778

# Submission time Handle Problem Language Result Execution time Memory
389778 2021-04-14T14:10:48 Z phathnv New Home (APIO18_new_home) C++11
5 / 100
2779 ms 1048580 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;
    }
};

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

void updateSeg(int l, int r, int x, int type){
    for(int i = 0; i < (int) xCoor.size(); i++)
        if (l <= xCoor[i] && xCoor[i] <= r){
            if (type == 1)
                val[i].insert(abs(x - xCoor[i]));
            else
                val[i].erase(val[i].find(abs(x - xCoor[i])));
        }
}

void updatePair(int l, int r, int type){
    int mid = (l + r) >> 1;
    updateSeg(l, mid, l, type);
    updateSeg(mid + 1, r, r, type);
}

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());

    for(int i = 1; i <= k; i++){
        color[i].insert(-INF);
        color[i].insert(INF);
        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);
            updatePair(l, e.x, -1);
            updatePair(e.x, r, -1);
            updatePair(l, r, 1);
        } else if (e.type == 1){
            auto it = color[e.ind].upper_bound(e.x);
            int r = *it;
            int l = *(--it);
            updatePair(l, r, -1);
            updatePair(l, e.x, 1);
            updatePair(e.x, r, 1);
            color[e.ind].insert(e.x);
        } else {
            int p = lower_bound(xCoor.begin(), xCoor.end(), e.x) - xCoor.begin();
            answer[e.ind] = *(--val[p].end());
        }
    }
    for(int i = 1; i <= q; i++)
        cout << (answer[i] > 1e8? -1 : answer[i]) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 28492 KB Output is correct
2 Correct 18 ms 28492 KB Output is correct
3 Correct 18 ms 28504 KB Output is correct
4 Correct 18 ms 28508 KB Output is correct
5 Correct 19 ms 28516 KB Output is correct
6 Correct 28 ms 28668 KB Output is correct
7 Correct 89 ms 36016 KB Output is correct
8 Correct 64 ms 31076 KB Output is correct
9 Correct 99 ms 36036 KB Output is correct
10 Correct 25 ms 28748 KB Output is correct
11 Correct 38 ms 28880 KB Output is correct
12 Correct 24 ms 28624 KB Output is correct
13 Correct 36 ms 28556 KB Output is correct
14 Correct 30 ms 28492 KB Output is correct
15 Correct 61 ms 31308 KB Output is correct
16 Correct 69 ms 32668 KB Output is correct
17 Correct 50 ms 29636 KB Output is correct
18 Correct 69 ms 31440 KB Output is correct
19 Correct 72 ms 32608 KB Output is correct
20 Correct 54 ms 29772 KB Output is correct
21 Correct 19 ms 28616 KB Output is correct
22 Correct 100 ms 36036 KB Output is correct
23 Correct 78 ms 32428 KB Output is correct
24 Correct 71 ms 31052 KB Output is correct
25 Correct 53 ms 29388 KB Output is correct
26 Correct 33 ms 28620 KB Output is correct
27 Correct 24 ms 28620 KB Output is correct
28 Correct 35 ms 28648 KB Output is correct
29 Correct 33 ms 28628 KB Output is correct
30 Correct 29 ms 28536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 28492 KB Output is correct
2 Correct 18 ms 28492 KB Output is correct
3 Correct 18 ms 28504 KB Output is correct
4 Correct 18 ms 28508 KB Output is correct
5 Correct 19 ms 28516 KB Output is correct
6 Correct 28 ms 28668 KB Output is correct
7 Correct 89 ms 36016 KB Output is correct
8 Correct 64 ms 31076 KB Output is correct
9 Correct 99 ms 36036 KB Output is correct
10 Correct 25 ms 28748 KB Output is correct
11 Correct 38 ms 28880 KB Output is correct
12 Correct 24 ms 28624 KB Output is correct
13 Correct 36 ms 28556 KB Output is correct
14 Correct 30 ms 28492 KB Output is correct
15 Correct 61 ms 31308 KB Output is correct
16 Correct 69 ms 32668 KB Output is correct
17 Correct 50 ms 29636 KB Output is correct
18 Correct 69 ms 31440 KB Output is correct
19 Correct 72 ms 32608 KB Output is correct
20 Correct 54 ms 29772 KB Output is correct
21 Correct 19 ms 28616 KB Output is correct
22 Correct 100 ms 36036 KB Output is correct
23 Correct 78 ms 32428 KB Output is correct
24 Correct 71 ms 31052 KB Output is correct
25 Correct 53 ms 29388 KB Output is correct
26 Correct 33 ms 28620 KB Output is correct
27 Correct 24 ms 28620 KB Output is correct
28 Correct 35 ms 28648 KB Output is correct
29 Correct 33 ms 28628 KB Output is correct
30 Correct 29 ms 28536 KB Output is correct
31 Runtime error 2779 ms 1048580 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2167 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2206 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 28492 KB Output is correct
2 Correct 18 ms 28492 KB Output is correct
3 Correct 18 ms 28504 KB Output is correct
4 Correct 18 ms 28508 KB Output is correct
5 Correct 19 ms 28516 KB Output is correct
6 Correct 28 ms 28668 KB Output is correct
7 Correct 89 ms 36016 KB Output is correct
8 Correct 64 ms 31076 KB Output is correct
9 Correct 99 ms 36036 KB Output is correct
10 Correct 25 ms 28748 KB Output is correct
11 Correct 38 ms 28880 KB Output is correct
12 Correct 24 ms 28624 KB Output is correct
13 Correct 36 ms 28556 KB Output is correct
14 Correct 30 ms 28492 KB Output is correct
15 Correct 61 ms 31308 KB Output is correct
16 Correct 69 ms 32668 KB Output is correct
17 Correct 50 ms 29636 KB Output is correct
18 Correct 69 ms 31440 KB Output is correct
19 Correct 72 ms 32608 KB Output is correct
20 Correct 54 ms 29772 KB Output is correct
21 Correct 19 ms 28616 KB Output is correct
22 Correct 100 ms 36036 KB Output is correct
23 Correct 78 ms 32428 KB Output is correct
24 Correct 71 ms 31052 KB Output is correct
25 Correct 53 ms 29388 KB Output is correct
26 Correct 33 ms 28620 KB Output is correct
27 Correct 24 ms 28620 KB Output is correct
28 Correct 35 ms 28648 KB Output is correct
29 Correct 33 ms 28628 KB Output is correct
30 Correct 29 ms 28536 KB Output is correct
31 Runtime error 2779 ms 1048580 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 28492 KB Output is correct
2 Correct 18 ms 28492 KB Output is correct
3 Correct 18 ms 28504 KB Output is correct
4 Correct 18 ms 28508 KB Output is correct
5 Correct 19 ms 28516 KB Output is correct
6 Correct 28 ms 28668 KB Output is correct
7 Correct 89 ms 36016 KB Output is correct
8 Correct 64 ms 31076 KB Output is correct
9 Correct 99 ms 36036 KB Output is correct
10 Correct 25 ms 28748 KB Output is correct
11 Correct 38 ms 28880 KB Output is correct
12 Correct 24 ms 28624 KB Output is correct
13 Correct 36 ms 28556 KB Output is correct
14 Correct 30 ms 28492 KB Output is correct
15 Correct 61 ms 31308 KB Output is correct
16 Correct 69 ms 32668 KB Output is correct
17 Correct 50 ms 29636 KB Output is correct
18 Correct 69 ms 31440 KB Output is correct
19 Correct 72 ms 32608 KB Output is correct
20 Correct 54 ms 29772 KB Output is correct
21 Correct 19 ms 28616 KB Output is correct
22 Correct 100 ms 36036 KB Output is correct
23 Correct 78 ms 32428 KB Output is correct
24 Correct 71 ms 31052 KB Output is correct
25 Correct 53 ms 29388 KB Output is correct
26 Correct 33 ms 28620 KB Output is correct
27 Correct 24 ms 28620 KB Output is correct
28 Correct 35 ms 28648 KB Output is correct
29 Correct 33 ms 28628 KB Output is correct
30 Correct 29 ms 28536 KB Output is correct
31 Runtime error 2779 ms 1048580 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -