This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, k, q, i, j, l, y, cur, x[300001], t[300001], a[300001], b[300001], ans[300001];
vector<pair<pair<int, int>, pair<int, int>>> v, g[300001];
multiset<int> ms[300001];
signed main() {
cin.tie(0)->sync_with_stdio(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
cin >> n >> k >> q;
for (i = 1; i <= n; i++) {
cin >> x[i] >> t[i] >> a[i] >> b[i];
//g[t[i]].push_back({{a[i], b[i]}, x[i]});
v.push_back({{a[i], -1}, {x[i], t[i]}});
v.push_back({{b[i], q + 1}, {x[i], t[i]}});
}
for (i = 1; i <= k; i++) sort(g[i].begin(), g[i].end());
for (i = 0; i < q; i++) {
cin >> l >> y;
v.push_back({{y, i}, {l, -1}});
}
sort(v.begin(), v.end());
for (auto w : v) {
if (w.first.second == -1) ms[w.second.second].insert(w.second.first);
else if (w.first.second == q + 1) ms[w.second.second].erase(ms[w.second.second].find(w.second.first));
else {
y = w.first.first, l = w.second.first;
j = w.first.second;
ans[j] = 0;
for (i = 1; i <= k; i++) {
cur = 1e18;
auto it = ms[i].lower_bound(l);
if (it != ms[i].end()) cur = min(cur, abs(l - *it));
if (it != ms[i].begin()) {
it--;
cur = min(cur, abs(l - *it));
}
//cout << w.first.first << " " << w.second.first << " " << i << " " << cur << "\n";
if (cur >= 1e17) {
ans[j] = -1;
break;
}
ans[j] = max(ans[j], cur);
}
}
}
for (i = 0; i < q; i++) cout << ans[i] << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |