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>
#define fastInp ios_base::sync_with_stdio(0); cin.tie(0);
#define pii pair<int, int>
#define fr first
#define sc second
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define mk make_pair
using namespace std;
const int MAXN = (int)1e8 + 8;
const int INF = 1e9;
int x[MAXN];
int t[MAXN];
int a[MAXN];
int b[MAXN];
int n, k, q;
int get(int pos, int tiktak) {
set <int> st;
for (int i = 1; i <= n; i++) {
if (a[i] <= tiktak && tiktak <= b[i]) {
st.insert(t[i]);
}
}
if (szof(st) != k) {
return -1;
}
int mx = 0;
for (int type : st) {
int mn = INF;
for (int i = 1; i <= n; i++) {
if (a[i] <= tiktak && tiktak <= b[i] && t[i] == type) {
mn = min(mn, abs(pos - x[i]));
}
}
mx = max(mx, mn);
}
return mx;
}
signed main() {
fastInp;
cin >> n >> k >> q;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> t[i] >> a[i] >> b[i];
}
while (q--) {
int pos, tiktak;
cin >> pos >> tiktak;
cout << get(pos, tiktak) << endl;
}
}
/*
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
*/
# | 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... |