이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 | 
|---|
| 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... |