#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pll = pair<ll, ll>;
template <class T>
using vec = vector<T>;
template <class T>
using indexed_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define FOR(i, s, e) for (ll i = (ll)s; i < e; i++)
#define CFOR(i, s, e) for (ll i = (ll)s; i <= e; i++)
#define TRAV(e, a) for (const auto &e : a)
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << "ln" << __LINE__ << ": " << #x << " = " << x << endl;
template <class T, class = decay_t<decltype(*begin(declval<T>()))>,
class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &out, const T &obj) {
out << "[";
for (auto it = obj.begin(); it != obj.end(); it++) {
out << &", "[2 * (it == obj.begin())] << *it;
}
return out << "]";
}
template <class K, class V>
ostream &operator<<(ostream &out, const pair<K, V> &obj) {
return out << "(" << obj.first << ", " << obj.second << ")";
}
struct query {
ll op, x, t, y, id;
};
ostream &operator<<(ostream &out, const query &obj) {
return out << vec<ll>{obj.op, obj.x, obj.t, obj.y, obj.id};
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k, q;
cin >> n >> k >> q;
if (k <= 400) {
vec<query> queries;
queries.reserve(2 * n + q);
FOR(i, 0, n) {
ll x, t, a, b;
cin >> x >> t >> a >> b;
queries.push_back({0, x, t, a, i});
queries.push_back({1, x, t, b + 1, i});
}
FOR(i, 0, q) {
ll l, y;
cin >> l >> y;
queries.push_back({2, l, -1, y, i});
}
sort(all(queries), [&](const query &o1, const query &o2) {
return (o1.y == o2.y) ? o1.op < o2.op : o1.y < o2.y;
});
vec<indexed_set<pll>> ss(k + 1);
vec<ll> ans(q);
TRAV(e, queries) {
if (e.op == 0) {
ss[e.t].insert({e.x, e.id});
} else if (e.op == 1) {
ss[e.t].erase({e.x, e.id});
} else if (e.op == 2) {
ll best = 0;
CFOR(i, 1, k) {
ll mn = INT_MAX;
auto it = ss[i].lower_bound({e.x, INT_MIN});
if (it != ss[i].end()) mn = min(mn, it->first - e.x);
if (it != ss[i].begin())
mn = min(mn, e.x - prev(it)->first);
best = max(best, mn);
}
ans[e.id] = (best == INT_MAX ? -1 : best);
}
}
TRAV(e, ans) cout << e << "\n";
} else {
assert(false);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
500 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
500 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1563 ms |
15208 KB |
Output is correct |
32 |
Correct |
67 ms |
10836 KB |
Output is correct |
33 |
Correct |
133 ms |
12368 KB |
Output is correct |
34 |
Correct |
1230 ms |
12868 KB |
Output is correct |
35 |
Correct |
743 ms |
14900 KB |
Output is correct |
36 |
Correct |
165 ms |
14928 KB |
Output is correct |
37 |
Correct |
124 ms |
11376 KB |
Output is correct |
38 |
Correct |
77 ms |
11348 KB |
Output is correct |
39 |
Correct |
66 ms |
11176 KB |
Output is correct |
40 |
Correct |
68 ms |
11092 KB |
Output is correct |
41 |
Correct |
203 ms |
11344 KB |
Output is correct |
42 |
Correct |
263 ms |
11252 KB |
Output is correct |
43 |
Correct |
525 ms |
14416 KB |
Output is correct |
44 |
Correct |
175 ms |
11448 KB |
Output is correct |
45 |
Correct |
90 ms |
11348 KB |
Output is correct |
46 |
Correct |
55 ms |
11280 KB |
Output is correct |
47 |
Correct |
57 ms |
10856 KB |
Output is correct |
48 |
Correct |
47 ms |
10580 KB |
Output is correct |
49 |
Correct |
60 ms |
10836 KB |
Output is correct |
50 |
Correct |
158 ms |
11140 KB |
Output is correct |
51 |
Correct |
55 ms |
10832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
800 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
500 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1563 ms |
15208 KB |
Output is correct |
32 |
Correct |
67 ms |
10836 KB |
Output is correct |
33 |
Correct |
133 ms |
12368 KB |
Output is correct |
34 |
Correct |
1230 ms |
12868 KB |
Output is correct |
35 |
Correct |
743 ms |
14900 KB |
Output is correct |
36 |
Correct |
165 ms |
14928 KB |
Output is correct |
37 |
Correct |
124 ms |
11376 KB |
Output is correct |
38 |
Correct |
77 ms |
11348 KB |
Output is correct |
39 |
Correct |
66 ms |
11176 KB |
Output is correct |
40 |
Correct |
68 ms |
11092 KB |
Output is correct |
41 |
Correct |
203 ms |
11344 KB |
Output is correct |
42 |
Correct |
263 ms |
11252 KB |
Output is correct |
43 |
Correct |
525 ms |
14416 KB |
Output is correct |
44 |
Correct |
175 ms |
11448 KB |
Output is correct |
45 |
Correct |
90 ms |
11348 KB |
Output is correct |
46 |
Correct |
55 ms |
11280 KB |
Output is correct |
47 |
Correct |
57 ms |
10856 KB |
Output is correct |
48 |
Correct |
47 ms |
10580 KB |
Output is correct |
49 |
Correct |
60 ms |
10836 KB |
Output is correct |
50 |
Correct |
158 ms |
11140 KB |
Output is correct |
51 |
Correct |
55 ms |
10832 KB |
Output is correct |
52 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
500 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1563 ms |
15208 KB |
Output is correct |
32 |
Correct |
67 ms |
10836 KB |
Output is correct |
33 |
Correct |
133 ms |
12368 KB |
Output is correct |
34 |
Correct |
1230 ms |
12868 KB |
Output is correct |
35 |
Correct |
743 ms |
14900 KB |
Output is correct |
36 |
Correct |
165 ms |
14928 KB |
Output is correct |
37 |
Correct |
124 ms |
11376 KB |
Output is correct |
38 |
Correct |
77 ms |
11348 KB |
Output is correct |
39 |
Correct |
66 ms |
11176 KB |
Output is correct |
40 |
Correct |
68 ms |
11092 KB |
Output is correct |
41 |
Correct |
203 ms |
11344 KB |
Output is correct |
42 |
Correct |
263 ms |
11252 KB |
Output is correct |
43 |
Correct |
525 ms |
14416 KB |
Output is correct |
44 |
Correct |
175 ms |
11448 KB |
Output is correct |
45 |
Correct |
90 ms |
11348 KB |
Output is correct |
46 |
Correct |
55 ms |
11280 KB |
Output is correct |
47 |
Correct |
57 ms |
10856 KB |
Output is correct |
48 |
Correct |
47 ms |
10580 KB |
Output is correct |
49 |
Correct |
60 ms |
10836 KB |
Output is correct |
50 |
Correct |
158 ms |
11140 KB |
Output is correct |
51 |
Correct |
55 ms |
10832 KB |
Output is correct |
52 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
53 |
Halted |
0 ms |
0 KB |
- |