//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2)//,tune=native")
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 60 * 1000 + 23, MAXK = MAXN;
/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10
*/
int n, q, k, x[MAXN], t[MAXN], a[MAXN], b[MAXN], l[MAXN], y[MAXN], ans[MAXN];
vector<int> cy;
map<int, vector<int>> add, rem, qu;
map<int, map<int, int>> cnt;
set<int> s[MAXK];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> k >> q;
if (n >= MAXN || q >= MAXN || k >= MAXK) return 0;
for (int i = 0; i < n; i++) {
cin >> x[i] >> t[i] >> a[i] >> b[i];
cy.push_back(a[i]), cy.push_back(b[i]);
add[a[i]].push_back(i), rem[b[i]].push_back(i);
}
for (int i = 0; i < q; i++) {
cin >> l[i] >> y[i];
cy.push_back(y[i]);
qu[y[i]].push_back(i);
}
sort(cy.begin(), cy.end());
cy.resize(unique(cy.begin(), cy.end()) - cy.begin());
for (auto i : cy) {
for (auto j : add[i]) if (cnt[t[j]][x[j]]++ == 0) s[t[j]].insert(x[j]);
for (auto j : qu[i]) {
ans[j] = -1;
for (int chi = 1; chi <= k; chi++) {
int jav = INT_MAX;
auto tmp = s[chi].upper_bound(l[j]);
if (tmp != s[chi].end()) jav = *tmp - l[j];
if (tmp != s[chi].begin()) {
tmp--;
jav = min(jav, l[j] - *tmp);
}
ans[j] = max(ans[j], jav);
}
}
for (auto j : rem[i]) if (--cnt[t[j]][x[j]] == 0) s[t[j]].erase(x[j]);
}
for (int i = 0; i < q; i++) cout << (ans[i] == INT_MAX? -1: ans[i]) << '\n';
return 0;
}
Compilation message
cc1plus: error: attribute 'avx2)//' argument 'target' is unknown