#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;
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<int> xCoor;
vector<Event> events;
multiset<int> color[N], val[N];
void UpdatePair(int l, int r, int type){
l = lower_bound(xCoor.begin(), xCoor.end(), l) - xCoor.begin() + 1;
r = lower_bound(xCoor.begin(), xCoor.end(), r) - xCoor.begin() + 1;
if (type == -1)
val[l].erase(val[l].find(r));
else
val[l].insert(r);
ST.update(l, (val[l].empty()? 0 : *(--val[l].end())));
}
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;
xCoor.push_back(x);
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));
}
xCoor.push_back(-INF);
xCoor.push_back(INF);
sort(xCoor.begin(), xCoor.end());
xCoor.resize(unique(xCoor.begin(), xCoor.end()) - xCoor.begin());
sort(events.begin(), events.end());
ST.init(xCoor.size());
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 lo = 0, hi = 1e8;
answer[e.ind] = -1;
while (lo <= hi){
int mid = (lo + hi) >> 1;
int l = lower_bound(xCoor.begin(), xCoor.end(), e.x - mid) - xCoor.begin() + 1;
int r = upper_bound(xCoor.begin(), xCoor.end(), e.x + mid) - 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 |
19 ms |
28492 KB |
Output is correct |
2 |
Correct |
19 ms |
28492 KB |
Output is correct |
3 |
Correct |
20 ms |
28468 KB |
Output is correct |
4 |
Correct |
18 ms |
28504 KB |
Output is correct |
5 |
Correct |
19 ms |
28492 KB |
Output is correct |
6 |
Correct |
20 ms |
28588 KB |
Output is correct |
7 |
Correct |
20 ms |
28612 KB |
Output is correct |
8 |
Correct |
22 ms |
28616 KB |
Output is correct |
9 |
Correct |
24 ms |
28628 KB |
Output is correct |
10 |
Correct |
20 ms |
28516 KB |
Output is correct |
11 |
Correct |
20 ms |
28588 KB |
Output is correct |
12 |
Correct |
20 ms |
28492 KB |
Output is correct |
13 |
Correct |
20 ms |
28524 KB |
Output is correct |
14 |
Correct |
21 ms |
28492 KB |
Output is correct |
15 |
Correct |
20 ms |
28492 KB |
Output is correct |
16 |
Correct |
19 ms |
28492 KB |
Output is correct |
17 |
Correct |
20 ms |
28500 KB |
Output is correct |
18 |
Correct |
23 ms |
28492 KB |
Output is correct |
19 |
Correct |
20 ms |
28620 KB |
Output is correct |
20 |
Correct |
20 ms |
28492 KB |
Output is correct |
21 |
Correct |
19 ms |
28620 KB |
Output is correct |
22 |
Correct |
20 ms |
28620 KB |
Output is correct |
23 |
Correct |
21 ms |
28500 KB |
Output is correct |
24 |
Correct |
20 ms |
28492 KB |
Output is correct |
25 |
Correct |
20 ms |
28476 KB |
Output is correct |
26 |
Correct |
21 ms |
28592 KB |
Output is correct |
27 |
Correct |
20 ms |
28564 KB |
Output is correct |
28 |
Correct |
20 ms |
28492 KB |
Output is correct |
29 |
Correct |
21 ms |
28516 KB |
Output is correct |
30 |
Correct |
20 ms |
28492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
28492 KB |
Output is correct |
2 |
Correct |
19 ms |
28492 KB |
Output is correct |
3 |
Correct |
20 ms |
28468 KB |
Output is correct |
4 |
Correct |
18 ms |
28504 KB |
Output is correct |
5 |
Correct |
19 ms |
28492 KB |
Output is correct |
6 |
Correct |
20 ms |
28588 KB |
Output is correct |
7 |
Correct |
20 ms |
28612 KB |
Output is correct |
8 |
Correct |
22 ms |
28616 KB |
Output is correct |
9 |
Correct |
24 ms |
28628 KB |
Output is correct |
10 |
Correct |
20 ms |
28516 KB |
Output is correct |
11 |
Correct |
20 ms |
28588 KB |
Output is correct |
12 |
Correct |
20 ms |
28492 KB |
Output is correct |
13 |
Correct |
20 ms |
28524 KB |
Output is correct |
14 |
Correct |
21 ms |
28492 KB |
Output is correct |
15 |
Correct |
20 ms |
28492 KB |
Output is correct |
16 |
Correct |
19 ms |
28492 KB |
Output is correct |
17 |
Correct |
20 ms |
28500 KB |
Output is correct |
18 |
Correct |
23 ms |
28492 KB |
Output is correct |
19 |
Correct |
20 ms |
28620 KB |
Output is correct |
20 |
Correct |
20 ms |
28492 KB |
Output is correct |
21 |
Correct |
19 ms |
28620 KB |
Output is correct |
22 |
Correct |
20 ms |
28620 KB |
Output is correct |
23 |
Correct |
21 ms |
28500 KB |
Output is correct |
24 |
Correct |
20 ms |
28492 KB |
Output is correct |
25 |
Correct |
20 ms |
28476 KB |
Output is correct |
26 |
Correct |
21 ms |
28592 KB |
Output is correct |
27 |
Correct |
20 ms |
28564 KB |
Output is correct |
28 |
Correct |
20 ms |
28492 KB |
Output is correct |
29 |
Correct |
21 ms |
28516 KB |
Output is correct |
30 |
Correct |
20 ms |
28492 KB |
Output is correct |
31 |
Correct |
770 ms |
41780 KB |
Output is correct |
32 |
Correct |
215 ms |
35180 KB |
Output is correct |
33 |
Correct |
758 ms |
38056 KB |
Output is correct |
34 |
Correct |
704 ms |
38380 KB |
Output is correct |
35 |
Correct |
781 ms |
41732 KB |
Output is correct |
36 |
Correct |
814 ms |
41720 KB |
Output is correct |
37 |
Correct |
675 ms |
36520 KB |
Output is correct |
38 |
Correct |
682 ms |
36376 KB |
Output is correct |
39 |
Correct |
611 ms |
36204 KB |
Output is correct |
40 |
Correct |
628 ms |
36088 KB |
Output is correct |
41 |
Correct |
551 ms |
36476 KB |
Output is correct |
42 |
Correct |
511 ms |
36204 KB |
Output is correct |
43 |
Correct |
178 ms |
40340 KB |
Output is correct |
44 |
Correct |
547 ms |
36436 KB |
Output is correct |
45 |
Correct |
547 ms |
36408 KB |
Output is correct |
46 |
Correct |
578 ms |
36344 KB |
Output is correct |
47 |
Correct |
467 ms |
36136 KB |
Output is correct |
48 |
Correct |
490 ms |
35884 KB |
Output is correct |
49 |
Correct |
556 ms |
36080 KB |
Output is correct |
50 |
Correct |
517 ms |
36140 KB |
Output is correct |
51 |
Correct |
546 ms |
36020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4029 ms |
102588 KB |
Output is correct |
2 |
Execution timed out |
5031 ms |
90340 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4793 ms |
94048 KB |
Output is correct |
2 |
Correct |
1136 ms |
77896 KB |
Output is correct |
3 |
Execution timed out |
5077 ms |
90184 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
28492 KB |
Output is correct |
2 |
Correct |
19 ms |
28492 KB |
Output is correct |
3 |
Correct |
20 ms |
28468 KB |
Output is correct |
4 |
Correct |
18 ms |
28504 KB |
Output is correct |
5 |
Correct |
19 ms |
28492 KB |
Output is correct |
6 |
Correct |
20 ms |
28588 KB |
Output is correct |
7 |
Correct |
20 ms |
28612 KB |
Output is correct |
8 |
Correct |
22 ms |
28616 KB |
Output is correct |
9 |
Correct |
24 ms |
28628 KB |
Output is correct |
10 |
Correct |
20 ms |
28516 KB |
Output is correct |
11 |
Correct |
20 ms |
28588 KB |
Output is correct |
12 |
Correct |
20 ms |
28492 KB |
Output is correct |
13 |
Correct |
20 ms |
28524 KB |
Output is correct |
14 |
Correct |
21 ms |
28492 KB |
Output is correct |
15 |
Correct |
20 ms |
28492 KB |
Output is correct |
16 |
Correct |
19 ms |
28492 KB |
Output is correct |
17 |
Correct |
20 ms |
28500 KB |
Output is correct |
18 |
Correct |
23 ms |
28492 KB |
Output is correct |
19 |
Correct |
20 ms |
28620 KB |
Output is correct |
20 |
Correct |
20 ms |
28492 KB |
Output is correct |
21 |
Correct |
19 ms |
28620 KB |
Output is correct |
22 |
Correct |
20 ms |
28620 KB |
Output is correct |
23 |
Correct |
21 ms |
28500 KB |
Output is correct |
24 |
Correct |
20 ms |
28492 KB |
Output is correct |
25 |
Correct |
20 ms |
28476 KB |
Output is correct |
26 |
Correct |
21 ms |
28592 KB |
Output is correct |
27 |
Correct |
20 ms |
28564 KB |
Output is correct |
28 |
Correct |
20 ms |
28492 KB |
Output is correct |
29 |
Correct |
21 ms |
28516 KB |
Output is correct |
30 |
Correct |
20 ms |
28492 KB |
Output is correct |
31 |
Correct |
770 ms |
41780 KB |
Output is correct |
32 |
Correct |
215 ms |
35180 KB |
Output is correct |
33 |
Correct |
758 ms |
38056 KB |
Output is correct |
34 |
Correct |
704 ms |
38380 KB |
Output is correct |
35 |
Correct |
781 ms |
41732 KB |
Output is correct |
36 |
Correct |
814 ms |
41720 KB |
Output is correct |
37 |
Correct |
675 ms |
36520 KB |
Output is correct |
38 |
Correct |
682 ms |
36376 KB |
Output is correct |
39 |
Correct |
611 ms |
36204 KB |
Output is correct |
40 |
Correct |
628 ms |
36088 KB |
Output is correct |
41 |
Correct |
551 ms |
36476 KB |
Output is correct |
42 |
Correct |
511 ms |
36204 KB |
Output is correct |
43 |
Correct |
178 ms |
40340 KB |
Output is correct |
44 |
Correct |
547 ms |
36436 KB |
Output is correct |
45 |
Correct |
547 ms |
36408 KB |
Output is correct |
46 |
Correct |
578 ms |
36344 KB |
Output is correct |
47 |
Correct |
467 ms |
36136 KB |
Output is correct |
48 |
Correct |
490 ms |
35884 KB |
Output is correct |
49 |
Correct |
556 ms |
36080 KB |
Output is correct |
50 |
Correct |
517 ms |
36140 KB |
Output is correct |
51 |
Correct |
546 ms |
36020 KB |
Output is correct |
52 |
Correct |
684 ms |
49772 KB |
Output is correct |
53 |
Correct |
627 ms |
46216 KB |
Output is correct |
54 |
Correct |
618 ms |
44264 KB |
Output is correct |
55 |
Correct |
588 ms |
40808 KB |
Output is correct |
56 |
Correct |
585 ms |
43116 KB |
Output is correct |
57 |
Correct |
557 ms |
37480 KB |
Output is correct |
58 |
Correct |
572 ms |
40940 KB |
Output is correct |
59 |
Correct |
587 ms |
42972 KB |
Output is correct |
60 |
Correct |
540 ms |
37352 KB |
Output is correct |
61 |
Correct |
210 ms |
48708 KB |
Output is correct |
62 |
Correct |
666 ms |
49868 KB |
Output is correct |
63 |
Correct |
623 ms |
44780 KB |
Output is correct |
64 |
Correct |
632 ms |
42420 KB |
Output is correct |
65 |
Correct |
571 ms |
38188 KB |
Output is correct |
66 |
Correct |
574 ms |
36232 KB |
Output is correct |
67 |
Correct |
264 ms |
35300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
28492 KB |
Output is correct |
2 |
Correct |
19 ms |
28492 KB |
Output is correct |
3 |
Correct |
20 ms |
28468 KB |
Output is correct |
4 |
Correct |
18 ms |
28504 KB |
Output is correct |
5 |
Correct |
19 ms |
28492 KB |
Output is correct |
6 |
Correct |
20 ms |
28588 KB |
Output is correct |
7 |
Correct |
20 ms |
28612 KB |
Output is correct |
8 |
Correct |
22 ms |
28616 KB |
Output is correct |
9 |
Correct |
24 ms |
28628 KB |
Output is correct |
10 |
Correct |
20 ms |
28516 KB |
Output is correct |
11 |
Correct |
20 ms |
28588 KB |
Output is correct |
12 |
Correct |
20 ms |
28492 KB |
Output is correct |
13 |
Correct |
20 ms |
28524 KB |
Output is correct |
14 |
Correct |
21 ms |
28492 KB |
Output is correct |
15 |
Correct |
20 ms |
28492 KB |
Output is correct |
16 |
Correct |
19 ms |
28492 KB |
Output is correct |
17 |
Correct |
20 ms |
28500 KB |
Output is correct |
18 |
Correct |
23 ms |
28492 KB |
Output is correct |
19 |
Correct |
20 ms |
28620 KB |
Output is correct |
20 |
Correct |
20 ms |
28492 KB |
Output is correct |
21 |
Correct |
19 ms |
28620 KB |
Output is correct |
22 |
Correct |
20 ms |
28620 KB |
Output is correct |
23 |
Correct |
21 ms |
28500 KB |
Output is correct |
24 |
Correct |
20 ms |
28492 KB |
Output is correct |
25 |
Correct |
20 ms |
28476 KB |
Output is correct |
26 |
Correct |
21 ms |
28592 KB |
Output is correct |
27 |
Correct |
20 ms |
28564 KB |
Output is correct |
28 |
Correct |
20 ms |
28492 KB |
Output is correct |
29 |
Correct |
21 ms |
28516 KB |
Output is correct |
30 |
Correct |
20 ms |
28492 KB |
Output is correct |
31 |
Correct |
770 ms |
41780 KB |
Output is correct |
32 |
Correct |
215 ms |
35180 KB |
Output is correct |
33 |
Correct |
758 ms |
38056 KB |
Output is correct |
34 |
Correct |
704 ms |
38380 KB |
Output is correct |
35 |
Correct |
781 ms |
41732 KB |
Output is correct |
36 |
Correct |
814 ms |
41720 KB |
Output is correct |
37 |
Correct |
675 ms |
36520 KB |
Output is correct |
38 |
Correct |
682 ms |
36376 KB |
Output is correct |
39 |
Correct |
611 ms |
36204 KB |
Output is correct |
40 |
Correct |
628 ms |
36088 KB |
Output is correct |
41 |
Correct |
551 ms |
36476 KB |
Output is correct |
42 |
Correct |
511 ms |
36204 KB |
Output is correct |
43 |
Correct |
178 ms |
40340 KB |
Output is correct |
44 |
Correct |
547 ms |
36436 KB |
Output is correct |
45 |
Correct |
547 ms |
36408 KB |
Output is correct |
46 |
Correct |
578 ms |
36344 KB |
Output is correct |
47 |
Correct |
467 ms |
36136 KB |
Output is correct |
48 |
Correct |
490 ms |
35884 KB |
Output is correct |
49 |
Correct |
556 ms |
36080 KB |
Output is correct |
50 |
Correct |
517 ms |
36140 KB |
Output is correct |
51 |
Correct |
546 ms |
36020 KB |
Output is correct |
52 |
Correct |
4029 ms |
102588 KB |
Output is correct |
53 |
Execution timed out |
5031 ms |
90340 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |