#include<bits/stdc++.h>
using namespace std;
struct event {
int et, x, t, y, i;
bool operator < (const event & o) const {
if (y == o.y) return et < o.et; // open query close
return y < o.y;
}
};
vector<event> e;
set<pair<int,int>> s[500];
int ans[100100];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k, q; cin >> n >> k >> q;
assert(k < 500);
for (int i = 1; i <= n; i++) {
int x, t, a, b; cin >> x >> t >> a >> b;
e.push_back({1, x, t, a, i});
e.push_back({3, x, t, b, i});
}
for (int i = 1; i <= q; i++) {
int l, y; cin >> l >> y;
e.push_back({2, l, 0, y, i});
}
sort(e.begin(), e.end());
for (auto [et, x, t, y, i] : e) {
if (et == 1) s[t].insert({x, i});
if (et == 3) s[t].erase({x, i});
if (et == 2) {
for (int type = 1; type <= k; type++) {
if (s[type].empty()) {
ans[i] = -1;
break;
}
// int mn = 1e9;
// for (auto a : s[type]) {
// mn = min(mn, abs(x - a.first));
// }
auto a = s[type].lower_bound({x, 1e9});
auto b = next(a);
auto c = prev(a);
int mn = min(abs(x - a->first), abs(b->first-x));
mn = min(mn, abs(c->first-x));
ans[i] = max(ans[i], mn);
}
}
}
for (int i = 1; i <= q; i++) cout << ans[i] << endl;
return 0;
}
# |
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 |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
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 |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
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 |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
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 |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |