#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using oset = __gnu_pbds::tree<int, __gnu_pbds::null_type,
std::less<int>,
__gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update>;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int base = 1 << 16;
const int inf = 1e9;
oset t[base * 2];
vector<pair<int, int>> xc;
int k;
int tget(int l, int r, int v = 1, int cl = 0, int cr = base) {
if (l <= cl && cr <= r) {
return t[v].size() - t[v].order_of_key(r);
}
if (r <= cl || cr <= l) {
return 0;
}
int cc = (cl + cr) / 2;
return tget(l, r, v * 2, cl, cc) + tget(l, r, v * 2 + 1, cc, cr);
}
int get(int x) {
int L = -1, R = inf / 2;
map<pair<int, int>, int> bscache;
bool ok = false;
while (L + 1 < R) {
int C = (L + R) / 2;
int lb = lower_bound(xc.begin(), xc.end(), pair<int, int>{x - C, -1}) - xc.begin();
int rb = upper_bound(xc.begin(), xc.end(), pair<int, int>{x + C, inf}) - xc.begin();
auto q = pair<int, int>{lb, rb};
int cnt;
if (bscache.count(q)) {
cnt = bscache[q];
} else {
bscache[q] = cnt = tget(lb, rb);
}
assert(cnt <= k);
if (cnt >= k) {
R = C;
ok = true;
} else {
L = C;
}
}
if (!ok) {
return -1;
} else {
return R;
}
}
void tput(int v, int val) {
v += base;
while (v >= 1) {
int ss = -t[v].size();
t[v].insert(val);
ss += t[v].size();
assert(ss == 1);
v /= 2;
}
}
void tdel(int v, int val) {
v += base;
while (v >= 1) {
int ss = t[v].size();
t[v].erase(val);
ss -= t[v].size();
assert(ss == 1);
v /= 2;
}
}
set<int> pos[base];
void put(int x, int t, int delta) {
if (delta == -1) {
auto it = pos[t].upper_bound(x);
int val = it == pos[t].end() ? inf + t : *it;
if (it != pos[t].begin()) {
--it;
tdel(*it, val);
tput(*it, x);
}
pos[t].insert(x);
tput(x, val);
} else if (delta == 1) {
assert(pos[t].count(x));
auto it = pos[t].upper_bound(x);
int val = it == pos[t].end() ? inf + t : *it;
tdel(x, val);
pos[t].erase(x);
if (it != pos[t].begin()) {
--it;
tdel(*it, x);
tput(*it, val);
}
} else {
assert(false);
}
}
signed main() {
#ifdef LOCAL
assert(freopen("a.in", "r", stdin));
#endif
struct Event {
int tp, tm, x, t, id;
bool operator<(const Event& e) const {
if (tm != e.tm) {
return tm < e.tm;
}
return tp < e.tp;
}
};
int n, q;
cin >> n >> k >> q;
vector<Event> ev;
for (int i = 0; i < n; ++i) {
int x, t, a, b;
cin >> x >> t >> a >> b;
ev.push_back(Event{-1, a, x, t, i});
ev.push_back(Event{1, b, x, t, i});
xc.emplace_back(x, i);
}
sort(xc.begin(), xc.end());
for (int i = 0; i < q; ++i) {
int l, y;
cin >> l >> y;
ev.push_back(Event{0, y, l, -1, i});
}
sort(ev.begin(), ev.end());
vector<int> res(q);
for (auto& e : ev) {
if (e.tp == 0) {
res[e.id] = get(e.x);
} else {
auto sx = lower_bound(xc.begin(), xc.end(), pair<int, int>{e.x, e.id}) - xc.begin();
put(sx, e.t, e.tp);
}
}
for (int i = 0; i < q; ++i) {
cout << res[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
13620 KB |
Output is correct |
2 |
Correct |
16 ms |
13672 KB |
Output is correct |
3 |
Correct |
17 ms |
13748 KB |
Output is correct |
4 |
Correct |
16 ms |
13772 KB |
Output is correct |
5 |
Correct |
21 ms |
13944 KB |
Output is correct |
6 |
Correct |
24 ms |
14072 KB |
Output is correct |
7 |
Correct |
19 ms |
14072 KB |
Output is correct |
8 |
Correct |
24 ms |
14116 KB |
Output is correct |
9 |
Correct |
25 ms |
14244 KB |
Output is correct |
10 |
Correct |
28 ms |
14244 KB |
Output is correct |
11 |
Correct |
22 ms |
14244 KB |
Output is correct |
12 |
Correct |
33 ms |
14244 KB |
Output is correct |
13 |
Correct |
21 ms |
14244 KB |
Output is correct |
14 |
Correct |
27 ms |
14244 KB |
Output is correct |
15 |
Correct |
24 ms |
14244 KB |
Output is correct |
16 |
Correct |
24 ms |
14244 KB |
Output is correct |
17 |
Correct |
26 ms |
14244 KB |
Output is correct |
18 |
Correct |
25 ms |
14244 KB |
Output is correct |
19 |
Correct |
22 ms |
14244 KB |
Output is correct |
20 |
Correct |
26 ms |
14244 KB |
Output is correct |
21 |
Correct |
23 ms |
14244 KB |
Output is correct |
22 |
Correct |
24 ms |
14244 KB |
Output is correct |
23 |
Correct |
25 ms |
14244 KB |
Output is correct |
24 |
Correct |
27 ms |
14244 KB |
Output is correct |
25 |
Correct |
28 ms |
14244 KB |
Output is correct |
26 |
Correct |
23 ms |
14244 KB |
Output is correct |
27 |
Correct |
22 ms |
14244 KB |
Output is correct |
28 |
Correct |
22 ms |
14244 KB |
Output is correct |
29 |
Correct |
21 ms |
14244 KB |
Output is correct |
30 |
Correct |
21 ms |
14244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
13620 KB |
Output is correct |
2 |
Correct |
16 ms |
13672 KB |
Output is correct |
3 |
Correct |
17 ms |
13748 KB |
Output is correct |
4 |
Correct |
16 ms |
13772 KB |
Output is correct |
5 |
Correct |
21 ms |
13944 KB |
Output is correct |
6 |
Correct |
24 ms |
14072 KB |
Output is correct |
7 |
Correct |
19 ms |
14072 KB |
Output is correct |
8 |
Correct |
24 ms |
14116 KB |
Output is correct |
9 |
Correct |
25 ms |
14244 KB |
Output is correct |
10 |
Correct |
28 ms |
14244 KB |
Output is correct |
11 |
Correct |
22 ms |
14244 KB |
Output is correct |
12 |
Correct |
33 ms |
14244 KB |
Output is correct |
13 |
Correct |
21 ms |
14244 KB |
Output is correct |
14 |
Correct |
27 ms |
14244 KB |
Output is correct |
15 |
Correct |
24 ms |
14244 KB |
Output is correct |
16 |
Correct |
24 ms |
14244 KB |
Output is correct |
17 |
Correct |
26 ms |
14244 KB |
Output is correct |
18 |
Correct |
25 ms |
14244 KB |
Output is correct |
19 |
Correct |
22 ms |
14244 KB |
Output is correct |
20 |
Correct |
26 ms |
14244 KB |
Output is correct |
21 |
Correct |
23 ms |
14244 KB |
Output is correct |
22 |
Correct |
24 ms |
14244 KB |
Output is correct |
23 |
Correct |
25 ms |
14244 KB |
Output is correct |
24 |
Correct |
27 ms |
14244 KB |
Output is correct |
25 |
Correct |
28 ms |
14244 KB |
Output is correct |
26 |
Correct |
23 ms |
14244 KB |
Output is correct |
27 |
Correct |
22 ms |
14244 KB |
Output is correct |
28 |
Correct |
22 ms |
14244 KB |
Output is correct |
29 |
Correct |
21 ms |
14244 KB |
Output is correct |
30 |
Correct |
21 ms |
14244 KB |
Output is correct |
31 |
Execution timed out |
5010 ms |
69020 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
943 ms |
75628 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
943 ms |
76208 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
13620 KB |
Output is correct |
2 |
Correct |
16 ms |
13672 KB |
Output is correct |
3 |
Correct |
17 ms |
13748 KB |
Output is correct |
4 |
Correct |
16 ms |
13772 KB |
Output is correct |
5 |
Correct |
21 ms |
13944 KB |
Output is correct |
6 |
Correct |
24 ms |
14072 KB |
Output is correct |
7 |
Correct |
19 ms |
14072 KB |
Output is correct |
8 |
Correct |
24 ms |
14116 KB |
Output is correct |
9 |
Correct |
25 ms |
14244 KB |
Output is correct |
10 |
Correct |
28 ms |
14244 KB |
Output is correct |
11 |
Correct |
22 ms |
14244 KB |
Output is correct |
12 |
Correct |
33 ms |
14244 KB |
Output is correct |
13 |
Correct |
21 ms |
14244 KB |
Output is correct |
14 |
Correct |
27 ms |
14244 KB |
Output is correct |
15 |
Correct |
24 ms |
14244 KB |
Output is correct |
16 |
Correct |
24 ms |
14244 KB |
Output is correct |
17 |
Correct |
26 ms |
14244 KB |
Output is correct |
18 |
Correct |
25 ms |
14244 KB |
Output is correct |
19 |
Correct |
22 ms |
14244 KB |
Output is correct |
20 |
Correct |
26 ms |
14244 KB |
Output is correct |
21 |
Correct |
23 ms |
14244 KB |
Output is correct |
22 |
Correct |
24 ms |
14244 KB |
Output is correct |
23 |
Correct |
25 ms |
14244 KB |
Output is correct |
24 |
Correct |
27 ms |
14244 KB |
Output is correct |
25 |
Correct |
28 ms |
14244 KB |
Output is correct |
26 |
Correct |
23 ms |
14244 KB |
Output is correct |
27 |
Correct |
22 ms |
14244 KB |
Output is correct |
28 |
Correct |
22 ms |
14244 KB |
Output is correct |
29 |
Correct |
21 ms |
14244 KB |
Output is correct |
30 |
Correct |
21 ms |
14244 KB |
Output is correct |
31 |
Execution timed out |
5010 ms |
69020 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
13620 KB |
Output is correct |
2 |
Correct |
16 ms |
13672 KB |
Output is correct |
3 |
Correct |
17 ms |
13748 KB |
Output is correct |
4 |
Correct |
16 ms |
13772 KB |
Output is correct |
5 |
Correct |
21 ms |
13944 KB |
Output is correct |
6 |
Correct |
24 ms |
14072 KB |
Output is correct |
7 |
Correct |
19 ms |
14072 KB |
Output is correct |
8 |
Correct |
24 ms |
14116 KB |
Output is correct |
9 |
Correct |
25 ms |
14244 KB |
Output is correct |
10 |
Correct |
28 ms |
14244 KB |
Output is correct |
11 |
Correct |
22 ms |
14244 KB |
Output is correct |
12 |
Correct |
33 ms |
14244 KB |
Output is correct |
13 |
Correct |
21 ms |
14244 KB |
Output is correct |
14 |
Correct |
27 ms |
14244 KB |
Output is correct |
15 |
Correct |
24 ms |
14244 KB |
Output is correct |
16 |
Correct |
24 ms |
14244 KB |
Output is correct |
17 |
Correct |
26 ms |
14244 KB |
Output is correct |
18 |
Correct |
25 ms |
14244 KB |
Output is correct |
19 |
Correct |
22 ms |
14244 KB |
Output is correct |
20 |
Correct |
26 ms |
14244 KB |
Output is correct |
21 |
Correct |
23 ms |
14244 KB |
Output is correct |
22 |
Correct |
24 ms |
14244 KB |
Output is correct |
23 |
Correct |
25 ms |
14244 KB |
Output is correct |
24 |
Correct |
27 ms |
14244 KB |
Output is correct |
25 |
Correct |
28 ms |
14244 KB |
Output is correct |
26 |
Correct |
23 ms |
14244 KB |
Output is correct |
27 |
Correct |
22 ms |
14244 KB |
Output is correct |
28 |
Correct |
22 ms |
14244 KB |
Output is correct |
29 |
Correct |
21 ms |
14244 KB |
Output is correct |
30 |
Correct |
21 ms |
14244 KB |
Output is correct |
31 |
Execution timed out |
5010 ms |
69020 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |