#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int M = 3e5+5, MOD = 1e9+7;
struct event {int x, t, y, a;};
bool operator<(event a, event b) {if (a.y == b.y) return a.a < b.a; return a.y < b.y;};
int k, size, ans[M];//, ar[M*M];
//map<int, int> fr[M];
multiset<int> st[M];
int query(int ind) {
int mn = INT_MAX;
for (int i = 1; i <= k; i++) {
auto it = st[k].lower_bound(ind);
if (it != st[k].end()) mn = min(mn, *it - ind);
if (it != st[k].begin()) mn = min(mn, ind - *prev(it));
if (st[k].size() == 0) mn = -1;
} return mn;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, q;
cin >> n >> k >> q;
multiset<event> timeline;
for(int i = 1; i <= n; i++) {
int x, t, a, b;
cin >> x >> t >> a >> b;
timeline.insert({x, t, a, 0});
timeline.insert({x, t, b, 2});
}
for (int i = 1; i <= q; i++) {
int x, a;
cin >> x >> a;
timeline.insert({x, i, a, 1});
}
for (auto [x, color, y, type]:timeline) {
if (type == 0) {
// fr[x/size][color]++;
// ar[x]++;
st[color].insert(x);
} else if (type == 2) {
// fr[x/size][color]--;
// ar[x]--;
st[color].erase(st[color].find(x));
} else {
ans[color] = query(x);
}
}
for (int i = 1; i <= q; i++) cout << ans[i] << endl;
return 0;
}
/*
1 2 3 4 5 6 7 8
1 2 2 4 5 6 7 8
3
SRS RR SRRRS RRRR
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
------
2 1 3
1 1 1 4
1 1 2 5
1 3
1 5
1 7
------
1 1 1
100000000 1 1 1
1 1
------
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
8 ms |
14416 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
8 ms |
14416 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5057 ms |
110352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5051 ms |
110488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
8 ms |
14416 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
8 ms |
14416 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |