#include<bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n , k , q;
cin >> n >> k >> q;
vector < int > x(n), t(n), a(n), b(n);
vector < int > zipyear;
for(int i = 0; i < n; ++i){
cin >> x[i] >> t[i] >> a[i] >> b[i];
b[i]++;
zipyear.pb(a[i]), zipyear.pb(b[i]);
}
vector < pair < int , int >> que(q);
for(auto &i : que){
cin >> i.fi >> i.se;
zipyear.pb(i.se);
}
sort(all(zipyear)), zipyear.erase(unique(all(zipyear)), zipyear.end());
for(int i = 0; i < n; ++i){
a[i] = lower_bound(all(zipyear), a[i]) - zipyear.begin();
b[i] = lower_bound(all(zipyear), b[i]) - zipyear.begin();
}
for(int i = 0; i < q; ++i){
que[i].se = lower_bound(all(zipyear), que[i].se) - zipyear.begin();
}
vector < int > answer(q);
if(k <= 400){
multiset < int > type[k + 1];
vector < pair < int , int > > open[sz(zipyear) + 1];
vector < pair < int , int > > close[sz(zipyear) + 1];
vector < pair < int , int > > pr;
for(int i = 0; i < q; ++i)
pr.pb({que[i].se, i});
sort(all(pr));
int year = -1;
for(int i = 0; i < n; ++i){
open[a[i]].push_back({t[i], x[i]});
close[b[i]].push_back({t[i], x[i]});
}
/// inc
for(auto &i : pr){
while(year + 1 <= i.fi){
/// lol
for(auto &shop : open[year + 1]){
type[shop.fi].insert(shop.se);
}
/// lol
for(auto &shop : close[year + 1]){
type[shop.fi].erase(type[shop.fi].find(shop.se));
}
year++;
}
int ans = -1;
//
// cout << "LOL " << i.fi << ' ' << "\n";
// for(int t =1 ;t <=k; ++t){
// cout << "TYPE " << t << '\n';
// for(auto &u : type[t])
// cout << u << ' ';
// cout << endl;
// }
for(int t = 1;t <= k; ++t){
if(type[t].empty()){
ans = -1;
break;
}
int dist = 1e9;
auto it = type[t].lower_bound(que[i.se].fi);
if(it != type[t].end())
dist = min(dist , *it - que[i.se].fi);
if(it != type[t].begin()){
--it;
dist = min(dist , que[i.se].fi - *it);
}
ans = max(ans , dist);
}
answer[i.se] = ans;
}
}
for(int i = 0 ; i < q; ++i)
cout << answer[i] << '\n';
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
1 1 1
100000000 1 1 1
1 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
448 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
452 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
448 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
452 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1736 ms |
21512 KB |
Output is correct |
32 |
Correct |
80 ms |
6592 KB |
Output is correct |
33 |
Correct |
205 ms |
19812 KB |
Output is correct |
34 |
Correct |
1364 ms |
19848 KB |
Output is correct |
35 |
Correct |
813 ms |
21440 KB |
Output is correct |
36 |
Correct |
212 ms |
21396 KB |
Output is correct |
37 |
Correct |
179 ms |
18732 KB |
Output is correct |
38 |
Correct |
121 ms |
18752 KB |
Output is correct |
39 |
Correct |
103 ms |
18492 KB |
Output is correct |
40 |
Correct |
103 ms |
18476 KB |
Output is correct |
41 |
Correct |
264 ms |
18788 KB |
Output is correct |
42 |
Correct |
210 ms |
18652 KB |
Output is correct |
43 |
Correct |
170 ms |
9792 KB |
Output is correct |
44 |
Correct |
225 ms |
18844 KB |
Output is correct |
45 |
Correct |
142 ms |
18668 KB |
Output is correct |
46 |
Correct |
93 ms |
18720 KB |
Output is correct |
47 |
Correct |
81 ms |
17840 KB |
Output is correct |
48 |
Correct |
77 ms |
17724 KB |
Output is correct |
49 |
Correct |
91 ms |
18112 KB |
Output is correct |
50 |
Correct |
184 ms |
18484 KB |
Output is correct |
51 |
Correct |
85 ms |
18104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
266 ms |
26516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
311 ms |
25604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
448 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
452 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1736 ms |
21512 KB |
Output is correct |
32 |
Correct |
80 ms |
6592 KB |
Output is correct |
33 |
Correct |
205 ms |
19812 KB |
Output is correct |
34 |
Correct |
1364 ms |
19848 KB |
Output is correct |
35 |
Correct |
813 ms |
21440 KB |
Output is correct |
36 |
Correct |
212 ms |
21396 KB |
Output is correct |
37 |
Correct |
179 ms |
18732 KB |
Output is correct |
38 |
Correct |
121 ms |
18752 KB |
Output is correct |
39 |
Correct |
103 ms |
18492 KB |
Output is correct |
40 |
Correct |
103 ms |
18476 KB |
Output is correct |
41 |
Correct |
264 ms |
18788 KB |
Output is correct |
42 |
Correct |
210 ms |
18652 KB |
Output is correct |
43 |
Correct |
170 ms |
9792 KB |
Output is correct |
44 |
Correct |
225 ms |
18844 KB |
Output is correct |
45 |
Correct |
142 ms |
18668 KB |
Output is correct |
46 |
Correct |
93 ms |
18720 KB |
Output is correct |
47 |
Correct |
81 ms |
17840 KB |
Output is correct |
48 |
Correct |
77 ms |
17724 KB |
Output is correct |
49 |
Correct |
91 ms |
18112 KB |
Output is correct |
50 |
Correct |
184 ms |
18484 KB |
Output is correct |
51 |
Correct |
85 ms |
18104 KB |
Output is correct |
52 |
Incorrect |
72 ms |
5740 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
448 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
452 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1736 ms |
21512 KB |
Output is correct |
32 |
Correct |
80 ms |
6592 KB |
Output is correct |
33 |
Correct |
205 ms |
19812 KB |
Output is correct |
34 |
Correct |
1364 ms |
19848 KB |
Output is correct |
35 |
Correct |
813 ms |
21440 KB |
Output is correct |
36 |
Correct |
212 ms |
21396 KB |
Output is correct |
37 |
Correct |
179 ms |
18732 KB |
Output is correct |
38 |
Correct |
121 ms |
18752 KB |
Output is correct |
39 |
Correct |
103 ms |
18492 KB |
Output is correct |
40 |
Correct |
103 ms |
18476 KB |
Output is correct |
41 |
Correct |
264 ms |
18788 KB |
Output is correct |
42 |
Correct |
210 ms |
18652 KB |
Output is correct |
43 |
Correct |
170 ms |
9792 KB |
Output is correct |
44 |
Correct |
225 ms |
18844 KB |
Output is correct |
45 |
Correct |
142 ms |
18668 KB |
Output is correct |
46 |
Correct |
93 ms |
18720 KB |
Output is correct |
47 |
Correct |
81 ms |
17840 KB |
Output is correct |
48 |
Correct |
77 ms |
17724 KB |
Output is correct |
49 |
Correct |
91 ms |
18112 KB |
Output is correct |
50 |
Correct |
184 ms |
18484 KB |
Output is correct |
51 |
Correct |
85 ms |
18104 KB |
Output is correct |
52 |
Incorrect |
266 ms |
26516 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |