#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
int main(){
int nums, types, queries; cin >> nums >> types >> queries;
vector<ll> loc(nums), typ(nums);
vector<multiset<ll>> vloc(types + 1);
for (int t = 1; t <= types; t++){
vloc[t].insert(-inf); vloc[t].insert(inf);
}
vector<tuple<ll, int, bool>> events;
for (int i = 0; i < nums; i++){
ll a, b; cin >> loc[i] >> typ[i] >> a >> b;
events.push_back({a, i, 1});
events.push_back({b + 1, i, 0});
}
sort(events.begin(), events.end());
vector<tuple<ll, ll, int>> qlist(queries);
vector<ll> ans(queries);
for (int q = 0; q < queries; q++){
ll l, y; cin >> l >> y;
qlist[q] = {y, l, q};
}
sort(qlist.begin(), qlist.end());
int curr = 0;
for (auto &[y, x, q] : qlist){
while (curr != events.size() && get<0>(events[curr]) <= y){
ll yr; int ind; bool b; tie(yr, ind, b) = events[curr]; curr++;
if (b) vloc[typ[ind]].insert(loc[ind]);
else vloc[typ[ind]].erase(vloc[typ[ind]].find(loc[ind]));
}
ll res = 0;
for (int t = 1; t <= types; t++){
if (vloc[t].size() == 2){
res = -1;
break;
}
auto it = vloc[t].lower_bound(x);
res = max(res, min(*it - x, x - *prev(it)));
}
ans[q] = res;
}
for (ll x : ans) cout << x << '\n';
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<long long int, int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | while (curr != events.size() && get<0>(events[curr]) <= y){
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1579 ms |
9468 KB |
Output is correct |
32 |
Correct |
91 ms |
7364 KB |
Output is correct |
33 |
Correct |
180 ms |
9284 KB |
Output is correct |
34 |
Correct |
1239 ms |
9440 KB |
Output is correct |
35 |
Correct |
721 ms |
11204 KB |
Output is correct |
36 |
Correct |
204 ms |
10944 KB |
Output is correct |
37 |
Correct |
169 ms |
8640 KB |
Output is correct |
38 |
Correct |
128 ms |
8540 KB |
Output is correct |
39 |
Correct |
118 ms |
8132 KB |
Output is correct |
40 |
Correct |
118 ms |
8128 KB |
Output is correct |
41 |
Correct |
289 ms |
8624 KB |
Output is correct |
42 |
Correct |
233 ms |
8500 KB |
Output is correct |
43 |
Correct |
238 ms |
10860 KB |
Output is correct |
44 |
Correct |
255 ms |
8944 KB |
Output is correct |
45 |
Correct |
160 ms |
8388 KB |
Output is correct |
46 |
Correct |
109 ms |
8388 KB |
Output is correct |
47 |
Correct |
111 ms |
7976 KB |
Output is correct |
48 |
Correct |
103 ms |
7928 KB |
Output is correct |
49 |
Correct |
117 ms |
8132 KB |
Output is correct |
50 |
Correct |
213 ms |
8320 KB |
Output is correct |
51 |
Correct |
109 ms |
8196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5032 ms |
55728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5045 ms |
46872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1579 ms |
9468 KB |
Output is correct |
32 |
Correct |
91 ms |
7364 KB |
Output is correct |
33 |
Correct |
180 ms |
9284 KB |
Output is correct |
34 |
Correct |
1239 ms |
9440 KB |
Output is correct |
35 |
Correct |
721 ms |
11204 KB |
Output is correct |
36 |
Correct |
204 ms |
10944 KB |
Output is correct |
37 |
Correct |
169 ms |
8640 KB |
Output is correct |
38 |
Correct |
128 ms |
8540 KB |
Output is correct |
39 |
Correct |
118 ms |
8132 KB |
Output is correct |
40 |
Correct |
118 ms |
8128 KB |
Output is correct |
41 |
Correct |
289 ms |
8624 KB |
Output is correct |
42 |
Correct |
233 ms |
8500 KB |
Output is correct |
43 |
Correct |
238 ms |
10860 KB |
Output is correct |
44 |
Correct |
255 ms |
8944 KB |
Output is correct |
45 |
Correct |
160 ms |
8388 KB |
Output is correct |
46 |
Correct |
109 ms |
8388 KB |
Output is correct |
47 |
Correct |
111 ms |
7976 KB |
Output is correct |
48 |
Correct |
103 ms |
7928 KB |
Output is correct |
49 |
Correct |
117 ms |
8132 KB |
Output is correct |
50 |
Correct |
213 ms |
8320 KB |
Output is correct |
51 |
Correct |
109 ms |
8196 KB |
Output is correct |
52 |
Correct |
145 ms |
19400 KB |
Output is correct |
53 |
Correct |
128 ms |
17860 KB |
Output is correct |
54 |
Correct |
175 ms |
13760 KB |
Output is correct |
55 |
Execution timed out |
5062 ms |
11992 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1579 ms |
9468 KB |
Output is correct |
32 |
Correct |
91 ms |
7364 KB |
Output is correct |
33 |
Correct |
180 ms |
9284 KB |
Output is correct |
34 |
Correct |
1239 ms |
9440 KB |
Output is correct |
35 |
Correct |
721 ms |
11204 KB |
Output is correct |
36 |
Correct |
204 ms |
10944 KB |
Output is correct |
37 |
Correct |
169 ms |
8640 KB |
Output is correct |
38 |
Correct |
128 ms |
8540 KB |
Output is correct |
39 |
Correct |
118 ms |
8132 KB |
Output is correct |
40 |
Correct |
118 ms |
8128 KB |
Output is correct |
41 |
Correct |
289 ms |
8624 KB |
Output is correct |
42 |
Correct |
233 ms |
8500 KB |
Output is correct |
43 |
Correct |
238 ms |
10860 KB |
Output is correct |
44 |
Correct |
255 ms |
8944 KB |
Output is correct |
45 |
Correct |
160 ms |
8388 KB |
Output is correct |
46 |
Correct |
109 ms |
8388 KB |
Output is correct |
47 |
Correct |
111 ms |
7976 KB |
Output is correct |
48 |
Correct |
103 ms |
7928 KB |
Output is correct |
49 |
Correct |
117 ms |
8132 KB |
Output is correct |
50 |
Correct |
213 ms |
8320 KB |
Output is correct |
51 |
Correct |
109 ms |
8196 KB |
Output is correct |
52 |
Execution timed out |
5032 ms |
55728 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |