Submission #387601

#TimeUsernameProblemLanguageResultExecution timeMemory
387601milleniumEeeeNew Home (APIO18_new_home)C++17
5 / 100
5061 ms16144 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...