/*
Code written by Talant I.D.
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
int mod;
ll mode(ll a) {
a %= mod;
if (a < 0) a += mod;
return a;
}
ll subt(ll a, ll b) {
return mode(mode(a)-mode(b));
}
ll add(ll a, ll b) {
return mode(mode(a)+mode(b));
}
ll mult(ll a, ll b) {
return mode(mode(a)*mode(b));
}
ll binpow(ll a, ll b, ll m) {
ll res = 1;
while (b) {
if (b&1) res = ((res*a)%m+m)%m;
a = ((a*a)%m+m)%m;
b >>= 1;
}
return res;
}
void usaco(string s) {
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N = 3e5+7;
int ans[N];
multiset <int> pos[N];
int main() {
do_not_disturb
//~ usaco("marathon");
int n, q, k;
cin >> n >> k >> q;
vector <pair <pii, pii>> v;
for (int i = 0; i < n; i++) {
int x, type, a, b;
cin >> x >> type >> a >> b;
v.pb(mp(mp(a, b), mp(x, type)));
}
vector <pair <pii, int>> queries;
for (int i = 0; i < q; i++) {
int x, year;
cin >> x >> year;
for (int j = 1; j <= k; j++) pos[j].clear();
for (int j = 0; j < n; j++) {
if (v[j].first.first <= year && year <= v[j].first.second) {
pos[v[j].second.second].insert(v[j].second.first);
}
}
int mx = 0;
for (int j = 1; j <= k; j++) {
auto it = lb(all(pos[j]), x);
int it1 = 1e9+5e8, it2 = 1e9+5e8;
if (it != pos[j].end()) {
it1 = abs(*it-x);
}
if (it != pos[j].begin()) {
it--;
it2 = abs(*it-x);
}
mx = max(mx, min(it1, it2));
}
cout << (mx >= 1e9 ? -1 : mx) << endl;
queries.pb(mp(mp(year, x), i));
}
sort(all(queries)); sort(all(v));
return 0;
}
/*
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 6
1 3
1 5
1 7
*/
Compilation message
new_home.cpp: In function 'void usaco(std::string)':
new_home.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
57 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
58 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14412 KB |
Output is correct |
2 |
Correct |
9 ms |
14412 KB |
Output is correct |
3 |
Correct |
9 ms |
14412 KB |
Output is correct |
4 |
Correct |
9 ms |
14420 KB |
Output is correct |
5 |
Correct |
15 ms |
14452 KB |
Output is correct |
6 |
Correct |
14 ms |
14444 KB |
Output is correct |
7 |
Correct |
14 ms |
14444 KB |
Output is correct |
8 |
Correct |
16 ms |
14456 KB |
Output is correct |
9 |
Correct |
15 ms |
14412 KB |
Output is correct |
10 |
Correct |
18 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
10 ms |
14412 KB |
Output is correct |
13 |
Correct |
9 ms |
14412 KB |
Output is correct |
14 |
Correct |
10 ms |
14336 KB |
Output is correct |
15 |
Correct |
13 ms |
14412 KB |
Output is correct |
16 |
Correct |
14 ms |
14344 KB |
Output is correct |
17 |
Correct |
11 ms |
14412 KB |
Output is correct |
18 |
Correct |
13 ms |
14412 KB |
Output is correct |
19 |
Correct |
14 ms |
14444 KB |
Output is correct |
20 |
Correct |
14 ms |
14412 KB |
Output is correct |
21 |
Correct |
16 ms |
14456 KB |
Output is correct |
22 |
Correct |
15 ms |
14412 KB |
Output is correct |
23 |
Correct |
15 ms |
14440 KB |
Output is correct |
24 |
Correct |
14 ms |
14412 KB |
Output is correct |
25 |
Correct |
11 ms |
14444 KB |
Output is correct |
26 |
Correct |
10 ms |
14412 KB |
Output is correct |
27 |
Correct |
11 ms |
14412 KB |
Output is correct |
28 |
Correct |
10 ms |
14412 KB |
Output is correct |
29 |
Correct |
11 ms |
14440 KB |
Output is correct |
30 |
Correct |
9 ms |
14412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14412 KB |
Output is correct |
2 |
Correct |
9 ms |
14412 KB |
Output is correct |
3 |
Correct |
9 ms |
14412 KB |
Output is correct |
4 |
Correct |
9 ms |
14420 KB |
Output is correct |
5 |
Correct |
15 ms |
14452 KB |
Output is correct |
6 |
Correct |
14 ms |
14444 KB |
Output is correct |
7 |
Correct |
14 ms |
14444 KB |
Output is correct |
8 |
Correct |
16 ms |
14456 KB |
Output is correct |
9 |
Correct |
15 ms |
14412 KB |
Output is correct |
10 |
Correct |
18 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
10 ms |
14412 KB |
Output is correct |
13 |
Correct |
9 ms |
14412 KB |
Output is correct |
14 |
Correct |
10 ms |
14336 KB |
Output is correct |
15 |
Correct |
13 ms |
14412 KB |
Output is correct |
16 |
Correct |
14 ms |
14344 KB |
Output is correct |
17 |
Correct |
11 ms |
14412 KB |
Output is correct |
18 |
Correct |
13 ms |
14412 KB |
Output is correct |
19 |
Correct |
14 ms |
14444 KB |
Output is correct |
20 |
Correct |
14 ms |
14412 KB |
Output is correct |
21 |
Correct |
16 ms |
14456 KB |
Output is correct |
22 |
Correct |
15 ms |
14412 KB |
Output is correct |
23 |
Correct |
15 ms |
14440 KB |
Output is correct |
24 |
Correct |
14 ms |
14412 KB |
Output is correct |
25 |
Correct |
11 ms |
14444 KB |
Output is correct |
26 |
Correct |
10 ms |
14412 KB |
Output is correct |
27 |
Correct |
11 ms |
14412 KB |
Output is correct |
28 |
Correct |
10 ms |
14412 KB |
Output is correct |
29 |
Correct |
11 ms |
14440 KB |
Output is correct |
30 |
Correct |
9 ms |
14412 KB |
Output is correct |
31 |
Execution timed out |
5088 ms |
18084 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5065 ms |
33188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5089 ms |
33012 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14412 KB |
Output is correct |
2 |
Correct |
9 ms |
14412 KB |
Output is correct |
3 |
Correct |
9 ms |
14412 KB |
Output is correct |
4 |
Correct |
9 ms |
14420 KB |
Output is correct |
5 |
Correct |
15 ms |
14452 KB |
Output is correct |
6 |
Correct |
14 ms |
14444 KB |
Output is correct |
7 |
Correct |
14 ms |
14444 KB |
Output is correct |
8 |
Correct |
16 ms |
14456 KB |
Output is correct |
9 |
Correct |
15 ms |
14412 KB |
Output is correct |
10 |
Correct |
18 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
10 ms |
14412 KB |
Output is correct |
13 |
Correct |
9 ms |
14412 KB |
Output is correct |
14 |
Correct |
10 ms |
14336 KB |
Output is correct |
15 |
Correct |
13 ms |
14412 KB |
Output is correct |
16 |
Correct |
14 ms |
14344 KB |
Output is correct |
17 |
Correct |
11 ms |
14412 KB |
Output is correct |
18 |
Correct |
13 ms |
14412 KB |
Output is correct |
19 |
Correct |
14 ms |
14444 KB |
Output is correct |
20 |
Correct |
14 ms |
14412 KB |
Output is correct |
21 |
Correct |
16 ms |
14456 KB |
Output is correct |
22 |
Correct |
15 ms |
14412 KB |
Output is correct |
23 |
Correct |
15 ms |
14440 KB |
Output is correct |
24 |
Correct |
14 ms |
14412 KB |
Output is correct |
25 |
Correct |
11 ms |
14444 KB |
Output is correct |
26 |
Correct |
10 ms |
14412 KB |
Output is correct |
27 |
Correct |
11 ms |
14412 KB |
Output is correct |
28 |
Correct |
10 ms |
14412 KB |
Output is correct |
29 |
Correct |
11 ms |
14440 KB |
Output is correct |
30 |
Correct |
9 ms |
14412 KB |
Output is correct |
31 |
Execution timed out |
5088 ms |
18084 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14412 KB |
Output is correct |
2 |
Correct |
9 ms |
14412 KB |
Output is correct |
3 |
Correct |
9 ms |
14412 KB |
Output is correct |
4 |
Correct |
9 ms |
14420 KB |
Output is correct |
5 |
Correct |
15 ms |
14452 KB |
Output is correct |
6 |
Correct |
14 ms |
14444 KB |
Output is correct |
7 |
Correct |
14 ms |
14444 KB |
Output is correct |
8 |
Correct |
16 ms |
14456 KB |
Output is correct |
9 |
Correct |
15 ms |
14412 KB |
Output is correct |
10 |
Correct |
18 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
10 ms |
14412 KB |
Output is correct |
13 |
Correct |
9 ms |
14412 KB |
Output is correct |
14 |
Correct |
10 ms |
14336 KB |
Output is correct |
15 |
Correct |
13 ms |
14412 KB |
Output is correct |
16 |
Correct |
14 ms |
14344 KB |
Output is correct |
17 |
Correct |
11 ms |
14412 KB |
Output is correct |
18 |
Correct |
13 ms |
14412 KB |
Output is correct |
19 |
Correct |
14 ms |
14444 KB |
Output is correct |
20 |
Correct |
14 ms |
14412 KB |
Output is correct |
21 |
Correct |
16 ms |
14456 KB |
Output is correct |
22 |
Correct |
15 ms |
14412 KB |
Output is correct |
23 |
Correct |
15 ms |
14440 KB |
Output is correct |
24 |
Correct |
14 ms |
14412 KB |
Output is correct |
25 |
Correct |
11 ms |
14444 KB |
Output is correct |
26 |
Correct |
10 ms |
14412 KB |
Output is correct |
27 |
Correct |
11 ms |
14412 KB |
Output is correct |
28 |
Correct |
10 ms |
14412 KB |
Output is correct |
29 |
Correct |
11 ms |
14440 KB |
Output is correct |
30 |
Correct |
9 ms |
14412 KB |
Output is correct |
31 |
Execution timed out |
5088 ms |
18084 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |