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 lli long long int
#define debug(a) cout << #a <<  " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli> 
#define MAX_k 400
#define MAX 60000
#define INF (1ll<<60)
//para el vector de orden
#define year first
#define tipo second.first 
#define pos second.second 
lli n,q,k,a,b,c,d;
vector<pair<lli,pll>> orden;
multiset<lli> activos[MAX_k+2];
lli res[MAX];
//solucion de s1 y s2
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k >> q;
    rep(i,1,n) {
        cin >> a >> b >> c >> d;
        orden.push_back({c,{b,a}});
        orden.push_back({d+1,{-b,a}});
    }    
    rep(i,1,q) { //posicion y year
        cin >> a >> b;
        orden.push_back({b,{k+i,a}});
    }
    sort(orden.begin(), orden.end());
    for (auto act : orden) {
        if (act.tipo > k) {
            
            bool sepuede = true;
            act.tipo -= k;
            rep(i,1,k) {
                
                if (activos[i].empty()) {
                    sepuede = false;
                    break;
                }
                auto it  = activos[i].lower_bound(act.pos);
                a = INF;
                b = INF;
                if (it != activos[i].end()) a = (*it) - act.pos;
                if (it != activos[i].begin()) {
                    it--;
                    b = act.pos - (*it);
                }
                res[act.tipo] = max(res[act.tipo],min(a,b));
            }
            if (!sepuede) res[act.tipo] = -1;
        }
        else if (act.tipo < 0) {
            act.tipo *= (-1);
            activos[act.tipo].erase( activos[act.tipo].lower_bound(act.pos) );
        }
        else activos[act.tipo].insert(act.pos);
    }
    rep(i,1,q) cout << res[i] << "\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... |