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;
typedef long long ll;
const ll inf = 1e18;
int main(){
	int nums, types, queries; cin >> nums >> types >> queries;
	vector<ll> loc(nums), typ(nums);
	vector<multiset<ll>> vloc(types + 1);
	for (int t = 1; t <= types; t++){
		vloc[t].insert(-inf); vloc[t].insert(inf);
	}
	vector<tuple<ll, int, bool>> events;
	for (int i = 0; i < nums; i++){
		ll a, b; cin >> loc[i] >> typ[i] >> a >> b;
		events.push_back({a, i, 1});
		events.push_back({b + 1, i, 0});
	}
	sort(events.begin(), events.end());
	vector<tuple<ll, ll, int>> qlist(queries);
	vector<ll> ans(queries);
	for (int q = 0; q < queries; q++){
		ll l, y; cin >> l >> y;
		qlist[q] = {y, l, q};
	}
	sort(qlist.begin(), qlist.end());
	int curr = 0;
	for (auto &[y, x, q] : qlist){
		while (curr != events.size() && get<0>(events[curr]) <= y){
			ll yr; int ind; bool b; tie(yr, ind, b) = events[curr]; curr++;
			if (b) vloc[typ[ind]].insert(loc[ind]);
			else vloc[typ[ind]].erase(vloc[typ[ind]].find(loc[ind]));
		}
		ll res = 0;
		for (int t = 1; t <= types; t++){
			if (vloc[t].size() == 2){
				res = -1;
				break;
			}
			auto it = vloc[t].lower_bound(x);
			res = max(res, min(*it - x, x - *prev(it)));
		}
		ans[q] = res;
	}
	for (ll x : ans) cout << x << '\n';
}
Compilation message (stderr)
new_home.cpp: In function 'int main()':
new_home.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<long long int, int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   while (curr != events.size() && get<0>(events[curr]) <= y){
      |          ~~~~~^~~~~~~~~~~~~~~~| # | 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... |