#include <bits/stdc++.h>
using namespace std;
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
const int N = (int)3e5 + 7;
const int inf = (int)1e9 + 7;
int n, k, q;
int x[N], t[N], a[N], b[N];
multiset < int > s[404];
int ans[N];
struct query {
int type, x, t, y, ind;
query() {}
query(int _type, int _x, int _t, int _y) {
type = _type;
x = _x;
t = _t;
y = _y;
}
};
vector < query > vec;
bool cmp(query &A, query &B) {
if (A.y != B.y)
return A.y < B.y;
return A.type < B.type;
}
main() {
scanf("%d %d %d", &n, &k, &q);
for (int i = 1; i <= n; i++) {
scanf("%d %d %d %d", &x[i], &t[i], &a[i], &b[i]);
vec.pb(query(0, x[i], t[i], a[i]));
vec.pb(query(1, x[i], t[i], b[i] + 1));
}
for (int i = 1, l, y; i <= q; i++) {
scanf("%d %d", &l, &y);
vec.pb(query(2, l, 0, y));
vec.back().ind = i;
}
sort(all(vec), cmp);
for (auto to : vec) {
if (to.type == 0) {
s[to.t].insert(to.x);
} else if (to.type == 1) {
s[to.t].erase(s[to.t].find(to.x));
} else {
int res = -1;
for (int i = 1; i <= k; i++) {
if (s[i].empty()) {
res = -1;
break;
} else {
auto it = s[i].lower_bound(to.x);
int asd = inf;
if (it != s[i].end())
asd = min(asd, abs(to.x - (*it)));
if (it != s[i].begin()) {
it--;
asd = min(asd, abs(to.x - (*it)));
}
res = max(res, asd);
}
}
ans[to.ind] = res;
}
}
for (int i = 1; i <= q; i++) {
printf("%d\n", ans[i]);
}
}
Compilation message
new_home.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
39 | main() {
| ^~~~
new_home.cpp: In function 'int main()':
new_home.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d %d %d", &n, &k, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d %d %d %d", &x[i], &t[i], &a[i], &b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d %d", &l, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
416 KB |
Output is correct |
10 |
Correct |
1 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
416 KB |
Output is correct |
10 |
Correct |
1 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1721 ms |
11264 KB |
Output is correct |
32 |
Correct |
96 ms |
7400 KB |
Output is correct |
33 |
Correct |
149 ms |
9184 KB |
Output is correct |
34 |
Correct |
1383 ms |
9428 KB |
Output is correct |
35 |
Correct |
803 ms |
11216 KB |
Output is correct |
36 |
Correct |
174 ms |
10956 KB |
Output is correct |
37 |
Correct |
143 ms |
8636 KB |
Output is correct |
38 |
Correct |
97 ms |
8648 KB |
Output is correct |
39 |
Correct |
95 ms |
8616 KB |
Output is correct |
40 |
Correct |
87 ms |
8668 KB |
Output is correct |
41 |
Correct |
244 ms |
8816 KB |
Output is correct |
42 |
Correct |
185 ms |
8868 KB |
Output is correct |
43 |
Correct |
232 ms |
10748 KB |
Output is correct |
44 |
Correct |
201 ms |
8604 KB |
Output is correct |
45 |
Correct |
111 ms |
8632 KB |
Output is correct |
46 |
Correct |
74 ms |
8592 KB |
Output is correct |
47 |
Correct |
71 ms |
8612 KB |
Output is correct |
48 |
Correct |
72 ms |
8632 KB |
Output is correct |
49 |
Correct |
78 ms |
8632 KB |
Output is correct |
50 |
Correct |
161 ms |
8644 KB |
Output is correct |
51 |
Correct |
76 ms |
8552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
286 ms |
53828 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
318 ms |
54960 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
416 KB |
Output is correct |
10 |
Correct |
1 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1721 ms |
11264 KB |
Output is correct |
32 |
Correct |
96 ms |
7400 KB |
Output is correct |
33 |
Correct |
149 ms |
9184 KB |
Output is correct |
34 |
Correct |
1383 ms |
9428 KB |
Output is correct |
35 |
Correct |
803 ms |
11216 KB |
Output is correct |
36 |
Correct |
174 ms |
10956 KB |
Output is correct |
37 |
Correct |
143 ms |
8636 KB |
Output is correct |
38 |
Correct |
97 ms |
8648 KB |
Output is correct |
39 |
Correct |
95 ms |
8616 KB |
Output is correct |
40 |
Correct |
87 ms |
8668 KB |
Output is correct |
41 |
Correct |
244 ms |
8816 KB |
Output is correct |
42 |
Correct |
185 ms |
8868 KB |
Output is correct |
43 |
Correct |
232 ms |
10748 KB |
Output is correct |
44 |
Correct |
201 ms |
8604 KB |
Output is correct |
45 |
Correct |
111 ms |
8632 KB |
Output is correct |
46 |
Correct |
74 ms |
8592 KB |
Output is correct |
47 |
Correct |
71 ms |
8612 KB |
Output is correct |
48 |
Correct |
72 ms |
8632 KB |
Output is correct |
49 |
Correct |
78 ms |
8632 KB |
Output is correct |
50 |
Correct |
161 ms |
8644 KB |
Output is correct |
51 |
Correct |
76 ms |
8552 KB |
Output is correct |
52 |
Runtime error |
64 ms |
12848 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
416 KB |
Output is correct |
10 |
Correct |
1 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1721 ms |
11264 KB |
Output is correct |
32 |
Correct |
96 ms |
7400 KB |
Output is correct |
33 |
Correct |
149 ms |
9184 KB |
Output is correct |
34 |
Correct |
1383 ms |
9428 KB |
Output is correct |
35 |
Correct |
803 ms |
11216 KB |
Output is correct |
36 |
Correct |
174 ms |
10956 KB |
Output is correct |
37 |
Correct |
143 ms |
8636 KB |
Output is correct |
38 |
Correct |
97 ms |
8648 KB |
Output is correct |
39 |
Correct |
95 ms |
8616 KB |
Output is correct |
40 |
Correct |
87 ms |
8668 KB |
Output is correct |
41 |
Correct |
244 ms |
8816 KB |
Output is correct |
42 |
Correct |
185 ms |
8868 KB |
Output is correct |
43 |
Correct |
232 ms |
10748 KB |
Output is correct |
44 |
Correct |
201 ms |
8604 KB |
Output is correct |
45 |
Correct |
111 ms |
8632 KB |
Output is correct |
46 |
Correct |
74 ms |
8592 KB |
Output is correct |
47 |
Correct |
71 ms |
8612 KB |
Output is correct |
48 |
Correct |
72 ms |
8632 KB |
Output is correct |
49 |
Correct |
78 ms |
8632 KB |
Output is correct |
50 |
Correct |
161 ms |
8644 KB |
Output is correct |
51 |
Correct |
76 ms |
8552 KB |
Output is correct |
52 |
Runtime error |
286 ms |
53828 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |