# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59286 | Just_Solve_The_Problem | New Home (APIO18_new_home) | C++11 | 2780 ms | 118444 KiB |
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>
using namespace std;
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
const int N = (int)3e5 + 7;
const int inf = (int)1e9 + 7;
int n, k, q;
int x[N], t[N], a[N], b[N];
multiset < int > s[404];
int ans[N];
struct query {
int type, x, t, y, ind;
query() {}
query(int _type, int _x, int _t, int _y) {
type = _type;
x = _x;
t = _t;
y = _y;
}
};
vector < query > vec;
bool cmp(query &A, query &B) {
if (A.y != B.y)
return A.y < B.y;
return A.type < B.type;
}
main() {
scanf("%d %d %d", &n, &k, &q);
for (int i = 1; i <= n; i++) {
scanf("%d %d %d %d", &x[i], &t[i], &a[i], &b[i]);
vec.pb(query(0, x[i], t[i], a[i]));
vec.pb(query(1, x[i], t[i], b[i] + 1));
}
for (int i = 1, l, y; i <= q; i++) {
scanf("%d %d", &l, &y);
vec.pb(query(2, l, 0, y));
vec.back().ind = i;
}
sort(all(vec), cmp);
for (auto to : vec) {
if (to.type == 0) {
s[to.t].insert(to.x);
} else if (to.type == 1) {
s[to.t].erase(s[to.t].find(to.x));
} else {
int res = -1;
for (int i = 1; i <= k; i++) {
if (s[i].empty()) {
res = -1;
break;
} else {
auto it = s[i].lower_bound(to.x);
int asd = inf;
if (it != s[i].end())
asd = min(asd, abs(to.x - (*it)));
if (it != s[i].begin()) {
it--;
asd = min(asd, abs(to.x - (*it)));
}
res = max(res, asd);
}
}
ans[to.ind] = res;
}
}
for (int i = 1; i <= q; i++) {
printf("%d\n", ans[i]);
}
}
Compilation message (stderr)
# | 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... |