#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;
}
void sub12() {
for (int i = 1; i <= n; 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]);
}
}
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]);
}
if (n <= 6 * (int)1e4 && k <= 400) {
sub12();
return 0;
}
}
Compilation message
new_home.cpp:81:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
new_home.cpp: In function 'void sub12()':
new_home.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &l, &y);
~~~~~^~~~~~~~~~~~~~~~~
new_home.cpp: In function 'int main()':
new_home.cpp:82:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &n, &k, &q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &x[i], &t[i], &a[i], &b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
3 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
4 ms |
608 KB |
Output is correct |
7 |
Correct |
3 ms |
756 KB |
Output is correct |
8 |
Correct |
4 ms |
756 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
4 ms |
756 KB |
Output is correct |
11 |
Correct |
4 ms |
756 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
4 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
888 KB |
Output is correct |
15 |
Correct |
4 ms |
888 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
984 KB |
Output is correct |
18 |
Correct |
3 ms |
1008 KB |
Output is correct |
19 |
Correct |
3 ms |
1008 KB |
Output is correct |
20 |
Correct |
4 ms |
1052 KB |
Output is correct |
21 |
Correct |
3 ms |
1052 KB |
Output is correct |
22 |
Correct |
5 ms |
1088 KB |
Output is correct |
23 |
Correct |
4 ms |
1088 KB |
Output is correct |
24 |
Correct |
5 ms |
1128 KB |
Output is correct |
25 |
Correct |
3 ms |
1128 KB |
Output is correct |
26 |
Correct |
3 ms |
1128 KB |
Output is correct |
27 |
Correct |
3 ms |
1128 KB |
Output is correct |
28 |
Correct |
4 ms |
1128 KB |
Output is correct |
29 |
Correct |
4 ms |
1128 KB |
Output is correct |
30 |
Correct |
3 ms |
1128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
3 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
4 ms |
608 KB |
Output is correct |
7 |
Correct |
3 ms |
756 KB |
Output is correct |
8 |
Correct |
4 ms |
756 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
4 ms |
756 KB |
Output is correct |
11 |
Correct |
4 ms |
756 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
4 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
888 KB |
Output is correct |
15 |
Correct |
4 ms |
888 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
984 KB |
Output is correct |
18 |
Correct |
3 ms |
1008 KB |
Output is correct |
19 |
Correct |
3 ms |
1008 KB |
Output is correct |
20 |
Correct |
4 ms |
1052 KB |
Output is correct |
21 |
Correct |
3 ms |
1052 KB |
Output is correct |
22 |
Correct |
5 ms |
1088 KB |
Output is correct |
23 |
Correct |
4 ms |
1088 KB |
Output is correct |
24 |
Correct |
5 ms |
1128 KB |
Output is correct |
25 |
Correct |
3 ms |
1128 KB |
Output is correct |
26 |
Correct |
3 ms |
1128 KB |
Output is correct |
27 |
Correct |
3 ms |
1128 KB |
Output is correct |
28 |
Correct |
4 ms |
1128 KB |
Output is correct |
29 |
Correct |
4 ms |
1128 KB |
Output is correct |
30 |
Correct |
3 ms |
1128 KB |
Output is correct |
31 |
Correct |
3232 ms |
9744 KB |
Output is correct |
32 |
Correct |
123 ms |
9744 KB |
Output is correct |
33 |
Correct |
281 ms |
9744 KB |
Output is correct |
34 |
Correct |
2943 ms |
9744 KB |
Output is correct |
35 |
Correct |
1624 ms |
9876 KB |
Output is correct |
36 |
Correct |
417 ms |
9876 KB |
Output is correct |
37 |
Correct |
260 ms |
9876 KB |
Output is correct |
38 |
Correct |
137 ms |
9876 KB |
Output is correct |
39 |
Correct |
154 ms |
9876 KB |
Output is correct |
40 |
Correct |
159 ms |
9876 KB |
Output is correct |
41 |
Correct |
391 ms |
9876 KB |
Output is correct |
42 |
Correct |
327 ms |
9876 KB |
Output is correct |
43 |
Correct |
512 ms |
9968 KB |
Output is correct |
44 |
Correct |
320 ms |
9968 KB |
Output is correct |
45 |
Correct |
204 ms |
9968 KB |
Output is correct |
46 |
Correct |
125 ms |
9968 KB |
Output is correct |
47 |
Correct |
124 ms |
9968 KB |
Output is correct |
48 |
Correct |
107 ms |
9968 KB |
Output is correct |
49 |
Correct |
128 ms |
9968 KB |
Output is correct |
50 |
Correct |
246 ms |
9968 KB |
Output is correct |
51 |
Correct |
111 ms |
9968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
162 ms |
9968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
168 ms |
9968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
3 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
4 ms |
608 KB |
Output is correct |
7 |
Correct |
3 ms |
756 KB |
Output is correct |
8 |
Correct |
4 ms |
756 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
4 ms |
756 KB |
Output is correct |
11 |
Correct |
4 ms |
756 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
4 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
888 KB |
Output is correct |
15 |
Correct |
4 ms |
888 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
984 KB |
Output is correct |
18 |
Correct |
3 ms |
1008 KB |
Output is correct |
19 |
Correct |
3 ms |
1008 KB |
Output is correct |
20 |
Correct |
4 ms |
1052 KB |
Output is correct |
21 |
Correct |
3 ms |
1052 KB |
Output is correct |
22 |
Correct |
5 ms |
1088 KB |
Output is correct |
23 |
Correct |
4 ms |
1088 KB |
Output is correct |
24 |
Correct |
5 ms |
1128 KB |
Output is correct |
25 |
Correct |
3 ms |
1128 KB |
Output is correct |
26 |
Correct |
3 ms |
1128 KB |
Output is correct |
27 |
Correct |
3 ms |
1128 KB |
Output is correct |
28 |
Correct |
4 ms |
1128 KB |
Output is correct |
29 |
Correct |
4 ms |
1128 KB |
Output is correct |
30 |
Correct |
3 ms |
1128 KB |
Output is correct |
31 |
Correct |
3232 ms |
9744 KB |
Output is correct |
32 |
Correct |
123 ms |
9744 KB |
Output is correct |
33 |
Correct |
281 ms |
9744 KB |
Output is correct |
34 |
Correct |
2943 ms |
9744 KB |
Output is correct |
35 |
Correct |
1624 ms |
9876 KB |
Output is correct |
36 |
Correct |
417 ms |
9876 KB |
Output is correct |
37 |
Correct |
260 ms |
9876 KB |
Output is correct |
38 |
Correct |
137 ms |
9876 KB |
Output is correct |
39 |
Correct |
154 ms |
9876 KB |
Output is correct |
40 |
Correct |
159 ms |
9876 KB |
Output is correct |
41 |
Correct |
391 ms |
9876 KB |
Output is correct |
42 |
Correct |
327 ms |
9876 KB |
Output is correct |
43 |
Correct |
512 ms |
9968 KB |
Output is correct |
44 |
Correct |
320 ms |
9968 KB |
Output is correct |
45 |
Correct |
204 ms |
9968 KB |
Output is correct |
46 |
Correct |
125 ms |
9968 KB |
Output is correct |
47 |
Correct |
124 ms |
9968 KB |
Output is correct |
48 |
Correct |
107 ms |
9968 KB |
Output is correct |
49 |
Correct |
128 ms |
9968 KB |
Output is correct |
50 |
Correct |
246 ms |
9968 KB |
Output is correct |
51 |
Correct |
111 ms |
9968 KB |
Output is correct |
52 |
Incorrect |
60 ms |
9968 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
3 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
4 ms |
608 KB |
Output is correct |
7 |
Correct |
3 ms |
756 KB |
Output is correct |
8 |
Correct |
4 ms |
756 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
4 ms |
756 KB |
Output is correct |
11 |
Correct |
4 ms |
756 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
4 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
888 KB |
Output is correct |
15 |
Correct |
4 ms |
888 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
984 KB |
Output is correct |
18 |
Correct |
3 ms |
1008 KB |
Output is correct |
19 |
Correct |
3 ms |
1008 KB |
Output is correct |
20 |
Correct |
4 ms |
1052 KB |
Output is correct |
21 |
Correct |
3 ms |
1052 KB |
Output is correct |
22 |
Correct |
5 ms |
1088 KB |
Output is correct |
23 |
Correct |
4 ms |
1088 KB |
Output is correct |
24 |
Correct |
5 ms |
1128 KB |
Output is correct |
25 |
Correct |
3 ms |
1128 KB |
Output is correct |
26 |
Correct |
3 ms |
1128 KB |
Output is correct |
27 |
Correct |
3 ms |
1128 KB |
Output is correct |
28 |
Correct |
4 ms |
1128 KB |
Output is correct |
29 |
Correct |
4 ms |
1128 KB |
Output is correct |
30 |
Correct |
3 ms |
1128 KB |
Output is correct |
31 |
Correct |
3232 ms |
9744 KB |
Output is correct |
32 |
Correct |
123 ms |
9744 KB |
Output is correct |
33 |
Correct |
281 ms |
9744 KB |
Output is correct |
34 |
Correct |
2943 ms |
9744 KB |
Output is correct |
35 |
Correct |
1624 ms |
9876 KB |
Output is correct |
36 |
Correct |
417 ms |
9876 KB |
Output is correct |
37 |
Correct |
260 ms |
9876 KB |
Output is correct |
38 |
Correct |
137 ms |
9876 KB |
Output is correct |
39 |
Correct |
154 ms |
9876 KB |
Output is correct |
40 |
Correct |
159 ms |
9876 KB |
Output is correct |
41 |
Correct |
391 ms |
9876 KB |
Output is correct |
42 |
Correct |
327 ms |
9876 KB |
Output is correct |
43 |
Correct |
512 ms |
9968 KB |
Output is correct |
44 |
Correct |
320 ms |
9968 KB |
Output is correct |
45 |
Correct |
204 ms |
9968 KB |
Output is correct |
46 |
Correct |
125 ms |
9968 KB |
Output is correct |
47 |
Correct |
124 ms |
9968 KB |
Output is correct |
48 |
Correct |
107 ms |
9968 KB |
Output is correct |
49 |
Correct |
128 ms |
9968 KB |
Output is correct |
50 |
Correct |
246 ms |
9968 KB |
Output is correct |
51 |
Correct |
111 ms |
9968 KB |
Output is correct |
52 |
Incorrect |
162 ms |
9968 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |