#include <cstdio>
#include <utility>
#include <algorithm>
#include <cstring>
#include <vector>
const int INF = 0x3f3f3f3f;
struct store {
int x, t, l, r;
bool operator<(store arg) {
return x < arg.x;
}
};
struct query {
int l, y, ind;
bool operator<(query arg) {
return y < arg.y;
}
};
bool cmp_l(query a, query b)
{
return a.l < b.l;
}
const int N = 300000;
const int K = 1000;
int n, k, q, next[N + 1], type_amt[N], ans[N], it[N], fi[N], last[N], right[N], to[N];
bool ut[N], active[N];
store a[N + 1];
query qr[N];
int main()
{
scanf("%d%d%d", &n, &k, &q);
a[n].x = INF;
next[n] = n;
memset(to, 0x3f, k << 2);
for (int i = 0; i < n; ++i) {
scanf("%d%d%d%d", &a[i].x, &a[i].t, &a[i].l, &a[i].r);
--a[i].t;
++a[i].r;
}
std::sort(a, a + n);
for (int i = 0; i < q; ++i) {
scanf("%d%d", &qr[i].l, &qr[i].y);
qr[i].ind = i;
}
std::sort(qr, qr + q);
for (int i = 0; i < q;) {
memset(ut, 0, k);
int until = std::min(i + K, q);
std::vector<int> inter, inter_type;
for (int j = 0; j < n; ++j) if (a[j].l >= qr[i].y + 1 && a[j].l <= qr[until - 1].y || a[j].r >= qr[i].y + 1 && a[j].r <= qr[until - 1].y) {
if (!ut[a[j].t]) {
inter_type.push_back(a[j].t);
fi[a[j].t] = n;
}
ut[a[j].t] = 1;
inter.push_back(j);
}
memset(last, -1, n << 2);
for (int j = 0; j < n; ++j) {
if (a[j].l <= qr[i].y && a[j].r > qr[until - 1].y) {
if (ut[a[j].t]) {
active[j] = false;
if (last[a[j].t] == -1) fi[a[j].t] = j;
else next[last[a[j].t]] = j;
last[a[j].t] = j;
next[j] = n;
}
else active[j] = true;
}
else active[j] = false;
}
memset(type_amt, 0, k << 2);
for (int j = 0, l = 0, amt = 0; j < n; ++j) {
while (l == j || l <= n && amt < k - inter_type.size()) {
if (l < n && active[l]) {
if (!type_amt[a[l].t]) ++amt;
++type_amt[a[l].t];
}
++l;
}
right[j] = l;
if (active[j]) {
--type_amt[a[j].t];
if (!type_amt[a[j].t]) --amt;
}
}
std::sort(qr + i, qr + until, cmp_l);
for (int j = 0; i < until; ++i) {
while (qr[i].l - a[j].x > a[right[j] - 1].x - qr[i].l) ++j;
int res = std::min(j ? qr[i].l - a[j - 1].x : INF, a[right[j] - 1].x - qr[i].l);
for (int k = 0; k < (int)inter.size(); ++k) if (a[inter[k]].l <= qr[i].y && a[inter[k]].r > qr[i].y) to[a[inter[k]].t] = std::min(to[a[inter[k]].t], abs(qr[i].l - a[inter[k]].x));
for (int k = 0; k < (int)inter_type.size(); ++k) {
while (a[next[fi[inter_type[k]]]].x <= qr[i].l) fi[inter_type[k]] = next[fi[inter_type[k]]];
res = std::max(res, std::min(to[inter_type[k]], std::min(abs(qr[i].l - a[fi[inter_type[k]]].x), a[next[fi[inter_type[k]]]].x - qr[i].l)));
to[inter_type[k]] = INF;
}
ans[qr[i].ind] = res > INF / 2 ? -1 : res;
}
}
for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
return 0;
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:56:57: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
56 | for (int j = 0; j < n; ++j) if (a[j].l >= qr[i].y + 1 && a[j].l <= qr[until - 1].y || a[j].r >= qr[i].y + 1 && a[j].r <= qr[until - 1].y) {
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:80:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | while (l == j || l <= n && amt < k - inter_type.size()) {
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:80:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
80 | while (l == j || l <= n && amt < k - inter_type.size()) {
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | 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", &a[i].x, &a[i].t, &a[i].l, &a[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d%d", &qr[i].l, &qr[i].y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
360 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
360 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1208 ms |
3368 KB |
Output is correct |
32 |
Correct |
790 ms |
3076 KB |
Output is correct |
33 |
Correct |
1241 ms |
3368 KB |
Output is correct |
34 |
Correct |
1403 ms |
3504 KB |
Output is correct |
35 |
Correct |
1113 ms |
3372 KB |
Output is correct |
36 |
Correct |
1092 ms |
3244 KB |
Output is correct |
37 |
Correct |
950 ms |
3372 KB |
Output is correct |
38 |
Correct |
965 ms |
3240 KB |
Output is correct |
39 |
Correct |
420 ms |
3004 KB |
Output is correct |
40 |
Correct |
622 ms |
3040 KB |
Output is correct |
41 |
Correct |
928 ms |
3240 KB |
Output is correct |
42 |
Correct |
1055 ms |
3232 KB |
Output is correct |
43 |
Correct |
82 ms |
3264 KB |
Output is correct |
44 |
Correct |
833 ms |
3256 KB |
Output is correct |
45 |
Correct |
471 ms |
3252 KB |
Output is correct |
46 |
Correct |
359 ms |
3252 KB |
Output is correct |
47 |
Correct |
145 ms |
2872 KB |
Output is correct |
48 |
Correct |
141 ms |
2860 KB |
Output is correct |
49 |
Correct |
227 ms |
2988 KB |
Output is correct |
50 |
Correct |
529 ms |
2940 KB |
Output is correct |
51 |
Correct |
278 ms |
3084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1303 ms |
15452 KB |
Output is correct |
2 |
Correct |
1645 ms |
13724 KB |
Output is correct |
3 |
Correct |
1596 ms |
17640 KB |
Output is correct |
4 |
Correct |
1413 ms |
15888 KB |
Output is correct |
5 |
Correct |
1469 ms |
13340 KB |
Output is correct |
6 |
Correct |
1722 ms |
13780 KB |
Output is correct |
7 |
Correct |
1496 ms |
17632 KB |
Output is correct |
8 |
Correct |
1524 ms |
15828 KB |
Output is correct |
9 |
Correct |
1464 ms |
15200 KB |
Output is correct |
10 |
Correct |
1380 ms |
14368 KB |
Output is correct |
11 |
Correct |
1463 ms |
13920 KB |
Output is correct |
12 |
Correct |
1558 ms |
14484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5093 ms |
13464 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
360 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1208 ms |
3368 KB |
Output is correct |
32 |
Correct |
790 ms |
3076 KB |
Output is correct |
33 |
Correct |
1241 ms |
3368 KB |
Output is correct |
34 |
Correct |
1403 ms |
3504 KB |
Output is correct |
35 |
Correct |
1113 ms |
3372 KB |
Output is correct |
36 |
Correct |
1092 ms |
3244 KB |
Output is correct |
37 |
Correct |
950 ms |
3372 KB |
Output is correct |
38 |
Correct |
965 ms |
3240 KB |
Output is correct |
39 |
Correct |
420 ms |
3004 KB |
Output is correct |
40 |
Correct |
622 ms |
3040 KB |
Output is correct |
41 |
Correct |
928 ms |
3240 KB |
Output is correct |
42 |
Correct |
1055 ms |
3232 KB |
Output is correct |
43 |
Correct |
82 ms |
3264 KB |
Output is correct |
44 |
Correct |
833 ms |
3256 KB |
Output is correct |
45 |
Correct |
471 ms |
3252 KB |
Output is correct |
46 |
Correct |
359 ms |
3252 KB |
Output is correct |
47 |
Correct |
145 ms |
2872 KB |
Output is correct |
48 |
Correct |
141 ms |
2860 KB |
Output is correct |
49 |
Correct |
227 ms |
2988 KB |
Output is correct |
50 |
Correct |
529 ms |
2940 KB |
Output is correct |
51 |
Correct |
278 ms |
3084 KB |
Output is correct |
52 |
Correct |
2000 ms |
3652 KB |
Output is correct |
53 |
Correct |
2156 ms |
3636 KB |
Output is correct |
54 |
Correct |
2222 ms |
3412 KB |
Output is correct |
55 |
Correct |
1215 ms |
3624 KB |
Output is correct |
56 |
Correct |
1228 ms |
3788 KB |
Output is correct |
57 |
Correct |
960 ms |
3332 KB |
Output is correct |
58 |
Correct |
1356 ms |
3652 KB |
Output is correct |
59 |
Correct |
1576 ms |
3648 KB |
Output is correct |
60 |
Correct |
1053 ms |
3444 KB |
Output is correct |
61 |
Correct |
81 ms |
3700 KB |
Output is correct |
62 |
Correct |
2045 ms |
3796 KB |
Output is correct |
63 |
Correct |
2155 ms |
3636 KB |
Output is correct |
64 |
Correct |
2234 ms |
3516 KB |
Output is correct |
65 |
Correct |
2216 ms |
3468 KB |
Output is correct |
66 |
Correct |
1354 ms |
3492 KB |
Output is correct |
67 |
Correct |
1856 ms |
3216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
360 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1208 ms |
3368 KB |
Output is correct |
32 |
Correct |
790 ms |
3076 KB |
Output is correct |
33 |
Correct |
1241 ms |
3368 KB |
Output is correct |
34 |
Correct |
1403 ms |
3504 KB |
Output is correct |
35 |
Correct |
1113 ms |
3372 KB |
Output is correct |
36 |
Correct |
1092 ms |
3244 KB |
Output is correct |
37 |
Correct |
950 ms |
3372 KB |
Output is correct |
38 |
Correct |
965 ms |
3240 KB |
Output is correct |
39 |
Correct |
420 ms |
3004 KB |
Output is correct |
40 |
Correct |
622 ms |
3040 KB |
Output is correct |
41 |
Correct |
928 ms |
3240 KB |
Output is correct |
42 |
Correct |
1055 ms |
3232 KB |
Output is correct |
43 |
Correct |
82 ms |
3264 KB |
Output is correct |
44 |
Correct |
833 ms |
3256 KB |
Output is correct |
45 |
Correct |
471 ms |
3252 KB |
Output is correct |
46 |
Correct |
359 ms |
3252 KB |
Output is correct |
47 |
Correct |
145 ms |
2872 KB |
Output is correct |
48 |
Correct |
141 ms |
2860 KB |
Output is correct |
49 |
Correct |
227 ms |
2988 KB |
Output is correct |
50 |
Correct |
529 ms |
2940 KB |
Output is correct |
51 |
Correct |
278 ms |
3084 KB |
Output is correct |
52 |
Correct |
1303 ms |
15452 KB |
Output is correct |
53 |
Correct |
1645 ms |
13724 KB |
Output is correct |
54 |
Correct |
1596 ms |
17640 KB |
Output is correct |
55 |
Correct |
1413 ms |
15888 KB |
Output is correct |
56 |
Correct |
1469 ms |
13340 KB |
Output is correct |
57 |
Correct |
1722 ms |
13780 KB |
Output is correct |
58 |
Correct |
1496 ms |
17632 KB |
Output is correct |
59 |
Correct |
1524 ms |
15828 KB |
Output is correct |
60 |
Correct |
1464 ms |
15200 KB |
Output is correct |
61 |
Correct |
1380 ms |
14368 KB |
Output is correct |
62 |
Correct |
1463 ms |
13920 KB |
Output is correct |
63 |
Correct |
1558 ms |
14484 KB |
Output is correct |
64 |
Execution timed out |
5093 ms |
13464 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |