#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fastIO() ios_base::sync_with_stdio(false), cin.tie(0)
const int INF = 0x7f7f7f7f;
const int maxn = 3E5 + 5;
struct Store {
int x, t, a, b, id;
};
struct Query {
int l, y, id;
};
int32_t main() {
fastIO();
int n, k, q;
cin >> n >> k >> q;
vector<Store> store(n);
for (int i = 0; i < n; ++i) {
cin >> store[i].x >> store[i].t >> store[i].a >> store[i].b;
store[i].id = i;
}
sort(ALL(store), [](auto s1, auto s2) {
if (s1.a == s2.a) return s1.b < s2.b;
return s1.a < s2.a;
});
vector<Query> ask(q);
for (int i = 0; i < q; ++i) {
cin >> ask[i].l >> ask[i].y;
ask[i].id = i;
}
sort(ALL(ask), [](auto q1, auto q2) {
if (q1.y == q2.y) return q1.l < q2.l;
return q1.y < q2.y;
});
vector<int> ans(q);
multiset<pii> pl[k + 1];
for (int j = 1; j <= k; ++j) pl[j].insert({-INF, INF}), pl[j].insert({INF, INF});
for (int i = 0, tok = 0; i < q; ++i) {
while (tok < n and store[tok].a <= ask[i].y) pl[store[tok].t].insert({store[tok].x, store[tok].b}), ++tok;
int maxDis = 0;
for (int j = 1; j <= k; ++j) {
auto it1 = pl[j].begin(), it2 = it1;
while ((it1 = pl[j].lower_bound({ask[i].l, 0LL}) , 1) and (*it1).Y < ask[i].y) pl[j].erase(it1);
while ((it2 = prev(pl[j].lower_bound({ask[i].l, 0LL})), 1) and (*it2).Y < ask[i].y) pl[j].erase(it2);
// for (auto qry : pl[j]) cout << "[" << qry.X << "," << qry.Y << "]"; cout << (*it1).X << " " << (*it2).X << "\n";
maxDis = max(maxDis, min(abs(ask[i].l - (*it1).X), abs(ask[i].l - (*it2).X)));
}
ans[ask[i].id] = maxDis > 1E8 ? -1 : maxDis;
}
for (auto x : ans) cout << x << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
4 ms |
512 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
4 ms |
512 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
3400 ms |
10488 KB |
Output is correct |
32 |
Correct |
82 ms |
7416 KB |
Output is correct |
33 |
Correct |
227 ms |
8184 KB |
Output is correct |
34 |
Correct |
2531 ms |
8440 KB |
Output is correct |
35 |
Correct |
1459 ms |
10512 KB |
Output is correct |
36 |
Correct |
276 ms |
10488 KB |
Output is correct |
37 |
Correct |
249 ms |
7032 KB |
Output is correct |
38 |
Correct |
124 ms |
6904 KB |
Output is correct |
39 |
Correct |
106 ms |
6648 KB |
Output is correct |
40 |
Correct |
107 ms |
6648 KB |
Output is correct |
41 |
Correct |
524 ms |
6904 KB |
Output is correct |
42 |
Correct |
673 ms |
6776 KB |
Output is correct |
43 |
Correct |
709 ms |
10744 KB |
Output is correct |
44 |
Correct |
446 ms |
6904 KB |
Output is correct |
45 |
Correct |
175 ms |
6776 KB |
Output is correct |
46 |
Correct |
89 ms |
6776 KB |
Output is correct |
47 |
Correct |
94 ms |
6392 KB |
Output is correct |
48 |
Correct |
87 ms |
6396 KB |
Output is correct |
49 |
Correct |
107 ms |
6520 KB |
Output is correct |
50 |
Correct |
383 ms |
6648 KB |
Output is correct |
51 |
Correct |
90 ms |
6648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5047 ms |
50544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5056 ms |
41336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
4 ms |
512 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
3400 ms |
10488 KB |
Output is correct |
32 |
Correct |
82 ms |
7416 KB |
Output is correct |
33 |
Correct |
227 ms |
8184 KB |
Output is correct |
34 |
Correct |
2531 ms |
8440 KB |
Output is correct |
35 |
Correct |
1459 ms |
10512 KB |
Output is correct |
36 |
Correct |
276 ms |
10488 KB |
Output is correct |
37 |
Correct |
249 ms |
7032 KB |
Output is correct |
38 |
Correct |
124 ms |
6904 KB |
Output is correct |
39 |
Correct |
106 ms |
6648 KB |
Output is correct |
40 |
Correct |
107 ms |
6648 KB |
Output is correct |
41 |
Correct |
524 ms |
6904 KB |
Output is correct |
42 |
Correct |
673 ms |
6776 KB |
Output is correct |
43 |
Correct |
709 ms |
10744 KB |
Output is correct |
44 |
Correct |
446 ms |
6904 KB |
Output is correct |
45 |
Correct |
175 ms |
6776 KB |
Output is correct |
46 |
Correct |
89 ms |
6776 KB |
Output is correct |
47 |
Correct |
94 ms |
6392 KB |
Output is correct |
48 |
Correct |
87 ms |
6396 KB |
Output is correct |
49 |
Correct |
107 ms |
6520 KB |
Output is correct |
50 |
Correct |
383 ms |
6648 KB |
Output is correct |
51 |
Correct |
90 ms |
6648 KB |
Output is correct |
52 |
Execution timed out |
5060 ms |
16508 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
4 ms |
512 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
3400 ms |
10488 KB |
Output is correct |
32 |
Correct |
82 ms |
7416 KB |
Output is correct |
33 |
Correct |
227 ms |
8184 KB |
Output is correct |
34 |
Correct |
2531 ms |
8440 KB |
Output is correct |
35 |
Correct |
1459 ms |
10512 KB |
Output is correct |
36 |
Correct |
276 ms |
10488 KB |
Output is correct |
37 |
Correct |
249 ms |
7032 KB |
Output is correct |
38 |
Correct |
124 ms |
6904 KB |
Output is correct |
39 |
Correct |
106 ms |
6648 KB |
Output is correct |
40 |
Correct |
107 ms |
6648 KB |
Output is correct |
41 |
Correct |
524 ms |
6904 KB |
Output is correct |
42 |
Correct |
673 ms |
6776 KB |
Output is correct |
43 |
Correct |
709 ms |
10744 KB |
Output is correct |
44 |
Correct |
446 ms |
6904 KB |
Output is correct |
45 |
Correct |
175 ms |
6776 KB |
Output is correct |
46 |
Correct |
89 ms |
6776 KB |
Output is correct |
47 |
Correct |
94 ms |
6392 KB |
Output is correct |
48 |
Correct |
87 ms |
6396 KB |
Output is correct |
49 |
Correct |
107 ms |
6520 KB |
Output is correct |
50 |
Correct |
383 ms |
6648 KB |
Output is correct |
51 |
Correct |
90 ms |
6648 KB |
Output is correct |
52 |
Execution timed out |
5047 ms |
50544 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |