이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
class bag {
private:
vector<multiset<int>> g;
public:
bag(int k) {
g.resize(k);
}
void add(int idx, int k) {
g[k].insert(idx);
}
void rem(int idx, int k) {
g[k].erase(g[k].find(idx));
}
//int qry(int lx, int rx) {
//}
int qry(int x) {
for (int k = 0; k < (int) g.size(); k++) {
if (g[k].empty()) {
return -1;
}
}
int ans = 0;
for (int k = 0; k < (int) g.size(); k++) {
auto lo = g[k].lower_bound(x);
if (lo == g[k].end()) {
ans = max(ans, abs(x - *prev(lo)));
} else if (lo == g[k].begin()) {
ans = max(ans, abs(x - *lo));
} else {
ans = max(ans, min(abs(x - *lo), abs(x - *prev(lo))));
}
}
return ans;
}
};
const int start = 0;
const int query = 1;
const int endd = 2;
class E {
public:
int op, x, ty, ti;
E(int opp, int xx, int tyy, int tii) {
op = opp;
x = xx;
ty = tyy;
ti = tii;
}
bool operator <(const E& o) {
if (ti == o.ti) {
return op < o.op;
}
return ti < o.ti;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, q;
cin >> n >> k >> q;
vector<E> events;
for (int i = 0; i < n; i++) {
int x, t, a, b;
cin >> x >> t >> a >> b;
--t;
events.emplace_back(E(start, x, t, a));
events.emplace_back(E(endd, x, t, b));
}
for (int i = 0; i < q; i++) {
int l, y;
cin >> l >> y;
events.emplace_back(E(query, l, i, y));
}
sort(events.begin(), events.end());
vector<int> ans(q);
bag mrsrtr(k);
for (int i = 0; i < (int) events.size(); i++) {
if (events[i].op == start) {
mrsrtr.add(events[i].x, events[i].ty);
} else if (events[i].op == query) {
//int l = -1, r = 1e8;
//while (r - l > 1) {
//int mid = (l + r) >> 1;
//if (mrsrtr.qry(max(events[i].x - mid, 0), min(events[i].x + mid, (int) 1e8)) == k) {
//r = mid;
//} else {
//l = mid;
//}
int r = mrsrtr.qry(events[i].x);
ans[events[i].ty] = r;
//}
} else {
mrsrtr.rem(events[i].x, events[i].ty);
}
}
for (int x : ans) {
cout << x << '\n';
}
return 0;
}
# | 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... |