#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
struct Store {
int x, t, a, b;
bool operator < (const Store other) {
return a < other.a;
}
};
struct Query {
int l, y, i;
bool operator < (const Query other) {
return y < other.y;
}
};
int n, k, q;
Store stores[400000];
int mini[400000];
int answer[400000];
void basicShit() {
while(q--) {
int l, y;
cin >> l >> y;
for(int i = 1; i <= k; i++) mini[i] = +oo;
for(int i = 0; i < n; i++)
if(stores[i].a <= y and y <= stores[i].b)
mini[stores[i].t] = min(mini[stores[i].t], abs(l - stores[i].x));
int inconvenience = 0;
for(int i = 1; i <= k; i++) inconvenience = max(inconvenience, mini[i]);
if(inconvenience == +oo) inconvenience = -1;
cout << inconvenience << '\n';
}
}
bool cmp(Store a,Store b){return a.b<b.b;}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> k >> q;
for(int i = 0; i < n; i++) cin >> stores[i].x >> stores[i].t >> stores[i].a >> stores[i].b;
vector<vector<Store>> S(k+1);
for(int i = 0; i < n; i++)
S[stores[i].t].push_back(stores[i]);
vector<Query> queries(q);
for(int i = 0; i < q; i++)
cin >> queries[i].l >> queries[i].y, queries[i].i = i;
for(int i = 1; i <= k; i++)
sort(S[i].begin(), S[i].end());
sort(queries.begin(), queries.end());
vector<int> curIndex(k+1, 0);
vector<map<int, int>> values(k+1);
vector<vector<Store>> rem(k+1);
for(int i = 0; i < n; i++) rem[stores[i].t].push_back(stores[i]);
for(int i = 1; i <= k; i++) sort(rem[i].begin(), rem[i].end(), cmp);
vector<int> curRem(k+1, 0);
for(Query query : queries) {
for(int i = 1; i <= k; i++) {
while(curIndex[i] < (int)S[i].size() and S[i][curIndex[i]].a <= query.y) {
values[i][S[i][curIndex[i]].x]++;
curIndex[i]++;
}
while(curRem[i] < (int)rem[i].size() and rem[i][curRem[i]].b < query.y) {
values[i][rem[i][curRem[i]].x]--;
auto it = values[i].find(rem[i][curRem[i]].x);
if(it->second == 0) values[i].erase(it);
curRem[i]++;
}
}
int inconvenience = 0;
for(int i = 1; i <= k; i++) {
int ina = +oo;
auto it = values[i].lower_bound(query.l);
if(it != values[i].end()) {
ina = min(ina, abs(query.l - it->first));
if(it != values[i].begin()) {
it--;
ina = min(ina, abs(query.l - it->first));
}
}
if(values[i].size())
ina = min(ina, abs(query.l - (*values[i].rbegin()).first));
inconvenience = max(inconvenience, ina);
}
if(inconvenience == +oo) inconvenience = -1;
answer[query.i] = inconvenience;
}
for(int i = 0; i < q; i++) cout << answer[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
532 KB |
Output is correct |
5 |
Correct |
3 ms |
532 KB |
Output is correct |
6 |
Correct |
3 ms |
532 KB |
Output is correct |
7 |
Correct |
5 ms |
532 KB |
Output is correct |
8 |
Correct |
3 ms |
536 KB |
Output is correct |
9 |
Correct |
5 ms |
792 KB |
Output is correct |
10 |
Correct |
3 ms |
792 KB |
Output is correct |
11 |
Correct |
3 ms |
792 KB |
Output is correct |
12 |
Correct |
3 ms |
792 KB |
Output is correct |
13 |
Correct |
2 ms |
792 KB |
Output is correct |
14 |
Correct |
2 ms |
792 KB |
Output is correct |
15 |
Correct |
3 ms |
792 KB |
Output is correct |
16 |
Correct |
4 ms |
792 KB |
Output is correct |
17 |
Correct |
3 ms |
792 KB |
Output is correct |
18 |
Correct |
3 ms |
792 KB |
Output is correct |
19 |
Correct |
4 ms |
792 KB |
Output is correct |
20 |
Correct |
3 ms |
792 KB |
Output is correct |
21 |
Correct |
5 ms |
792 KB |
Output is correct |
22 |
Correct |
4 ms |
792 KB |
Output is correct |
23 |
Correct |
4 ms |
792 KB |
Output is correct |
24 |
Correct |
3 ms |
792 KB |
Output is correct |
25 |
Correct |
3 ms |
792 KB |
Output is correct |
26 |
Correct |
3 ms |
792 KB |
Output is correct |
27 |
Correct |
2 ms |
792 KB |
Output is correct |
28 |
Correct |
2 ms |
792 KB |
Output is correct |
29 |
Correct |
3 ms |
792 KB |
Output is correct |
30 |
Correct |
2 ms |
792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
532 KB |
Output is correct |
5 |
Correct |
3 ms |
532 KB |
Output is correct |
6 |
Correct |
3 ms |
532 KB |
Output is correct |
7 |
Correct |
5 ms |
532 KB |
Output is correct |
8 |
Correct |
3 ms |
536 KB |
Output is correct |
9 |
Correct |
5 ms |
792 KB |
Output is correct |
10 |
Correct |
3 ms |
792 KB |
Output is correct |
11 |
Correct |
3 ms |
792 KB |
Output is correct |
12 |
Correct |
3 ms |
792 KB |
Output is correct |
13 |
Correct |
2 ms |
792 KB |
Output is correct |
14 |
Correct |
2 ms |
792 KB |
Output is correct |
15 |
Correct |
3 ms |
792 KB |
Output is correct |
16 |
Correct |
4 ms |
792 KB |
Output is correct |
17 |
Correct |
3 ms |
792 KB |
Output is correct |
18 |
Correct |
3 ms |
792 KB |
Output is correct |
19 |
Correct |
4 ms |
792 KB |
Output is correct |
20 |
Correct |
3 ms |
792 KB |
Output is correct |
21 |
Correct |
5 ms |
792 KB |
Output is correct |
22 |
Correct |
4 ms |
792 KB |
Output is correct |
23 |
Correct |
4 ms |
792 KB |
Output is correct |
24 |
Correct |
3 ms |
792 KB |
Output is correct |
25 |
Correct |
3 ms |
792 KB |
Output is correct |
26 |
Correct |
3 ms |
792 KB |
Output is correct |
27 |
Correct |
2 ms |
792 KB |
Output is correct |
28 |
Correct |
2 ms |
792 KB |
Output is correct |
29 |
Correct |
3 ms |
792 KB |
Output is correct |
30 |
Correct |
2 ms |
792 KB |
Output is correct |
31 |
Correct |
3966 ms |
8960 KB |
Output is correct |
32 |
Correct |
66 ms |
8960 KB |
Output is correct |
33 |
Correct |
233 ms |
10068 KB |
Output is correct |
34 |
Correct |
2918 ms |
14128 KB |
Output is correct |
35 |
Correct |
1534 ms |
17764 KB |
Output is correct |
36 |
Correct |
275 ms |
20672 KB |
Output is correct |
37 |
Correct |
204 ms |
21068 KB |
Output is correct |
38 |
Correct |
142 ms |
23968 KB |
Output is correct |
39 |
Correct |
101 ms |
26180 KB |
Output is correct |
40 |
Correct |
99 ms |
29516 KB |
Output is correct |
41 |
Correct |
418 ms |
32176 KB |
Output is correct |
42 |
Correct |
637 ms |
35664 KB |
Output is correct |
43 |
Correct |
339 ms |
38564 KB |
Output is correct |
44 |
Correct |
358 ms |
40992 KB |
Output is correct |
45 |
Correct |
177 ms |
43584 KB |
Output is correct |
46 |
Correct |
80 ms |
46348 KB |
Output is correct |
47 |
Correct |
76 ms |
48884 KB |
Output is correct |
48 |
Correct |
99 ms |
51788 KB |
Output is correct |
49 |
Correct |
94 ms |
54588 KB |
Output is correct |
50 |
Correct |
336 ms |
58520 KB |
Output is correct |
51 |
Correct |
80 ms |
60200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5009 ms |
99812 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5006 ms |
99812 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
532 KB |
Output is correct |
5 |
Correct |
3 ms |
532 KB |
Output is correct |
6 |
Correct |
3 ms |
532 KB |
Output is correct |
7 |
Correct |
5 ms |
532 KB |
Output is correct |
8 |
Correct |
3 ms |
536 KB |
Output is correct |
9 |
Correct |
5 ms |
792 KB |
Output is correct |
10 |
Correct |
3 ms |
792 KB |
Output is correct |
11 |
Correct |
3 ms |
792 KB |
Output is correct |
12 |
Correct |
3 ms |
792 KB |
Output is correct |
13 |
Correct |
2 ms |
792 KB |
Output is correct |
14 |
Correct |
2 ms |
792 KB |
Output is correct |
15 |
Correct |
3 ms |
792 KB |
Output is correct |
16 |
Correct |
4 ms |
792 KB |
Output is correct |
17 |
Correct |
3 ms |
792 KB |
Output is correct |
18 |
Correct |
3 ms |
792 KB |
Output is correct |
19 |
Correct |
4 ms |
792 KB |
Output is correct |
20 |
Correct |
3 ms |
792 KB |
Output is correct |
21 |
Correct |
5 ms |
792 KB |
Output is correct |
22 |
Correct |
4 ms |
792 KB |
Output is correct |
23 |
Correct |
4 ms |
792 KB |
Output is correct |
24 |
Correct |
3 ms |
792 KB |
Output is correct |
25 |
Correct |
3 ms |
792 KB |
Output is correct |
26 |
Correct |
3 ms |
792 KB |
Output is correct |
27 |
Correct |
2 ms |
792 KB |
Output is correct |
28 |
Correct |
2 ms |
792 KB |
Output is correct |
29 |
Correct |
3 ms |
792 KB |
Output is correct |
30 |
Correct |
2 ms |
792 KB |
Output is correct |
31 |
Correct |
3966 ms |
8960 KB |
Output is correct |
32 |
Correct |
66 ms |
8960 KB |
Output is correct |
33 |
Correct |
233 ms |
10068 KB |
Output is correct |
34 |
Correct |
2918 ms |
14128 KB |
Output is correct |
35 |
Correct |
1534 ms |
17764 KB |
Output is correct |
36 |
Correct |
275 ms |
20672 KB |
Output is correct |
37 |
Correct |
204 ms |
21068 KB |
Output is correct |
38 |
Correct |
142 ms |
23968 KB |
Output is correct |
39 |
Correct |
101 ms |
26180 KB |
Output is correct |
40 |
Correct |
99 ms |
29516 KB |
Output is correct |
41 |
Correct |
418 ms |
32176 KB |
Output is correct |
42 |
Correct |
637 ms |
35664 KB |
Output is correct |
43 |
Correct |
339 ms |
38564 KB |
Output is correct |
44 |
Correct |
358 ms |
40992 KB |
Output is correct |
45 |
Correct |
177 ms |
43584 KB |
Output is correct |
46 |
Correct |
80 ms |
46348 KB |
Output is correct |
47 |
Correct |
76 ms |
48884 KB |
Output is correct |
48 |
Correct |
99 ms |
51788 KB |
Output is correct |
49 |
Correct |
94 ms |
54588 KB |
Output is correct |
50 |
Correct |
336 ms |
58520 KB |
Output is correct |
51 |
Correct |
80 ms |
60200 KB |
Output is correct |
52 |
Execution timed out |
5093 ms |
99812 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
532 KB |
Output is correct |
5 |
Correct |
3 ms |
532 KB |
Output is correct |
6 |
Correct |
3 ms |
532 KB |
Output is correct |
7 |
Correct |
5 ms |
532 KB |
Output is correct |
8 |
Correct |
3 ms |
536 KB |
Output is correct |
9 |
Correct |
5 ms |
792 KB |
Output is correct |
10 |
Correct |
3 ms |
792 KB |
Output is correct |
11 |
Correct |
3 ms |
792 KB |
Output is correct |
12 |
Correct |
3 ms |
792 KB |
Output is correct |
13 |
Correct |
2 ms |
792 KB |
Output is correct |
14 |
Correct |
2 ms |
792 KB |
Output is correct |
15 |
Correct |
3 ms |
792 KB |
Output is correct |
16 |
Correct |
4 ms |
792 KB |
Output is correct |
17 |
Correct |
3 ms |
792 KB |
Output is correct |
18 |
Correct |
3 ms |
792 KB |
Output is correct |
19 |
Correct |
4 ms |
792 KB |
Output is correct |
20 |
Correct |
3 ms |
792 KB |
Output is correct |
21 |
Correct |
5 ms |
792 KB |
Output is correct |
22 |
Correct |
4 ms |
792 KB |
Output is correct |
23 |
Correct |
4 ms |
792 KB |
Output is correct |
24 |
Correct |
3 ms |
792 KB |
Output is correct |
25 |
Correct |
3 ms |
792 KB |
Output is correct |
26 |
Correct |
3 ms |
792 KB |
Output is correct |
27 |
Correct |
2 ms |
792 KB |
Output is correct |
28 |
Correct |
2 ms |
792 KB |
Output is correct |
29 |
Correct |
3 ms |
792 KB |
Output is correct |
30 |
Correct |
2 ms |
792 KB |
Output is correct |
31 |
Correct |
3966 ms |
8960 KB |
Output is correct |
32 |
Correct |
66 ms |
8960 KB |
Output is correct |
33 |
Correct |
233 ms |
10068 KB |
Output is correct |
34 |
Correct |
2918 ms |
14128 KB |
Output is correct |
35 |
Correct |
1534 ms |
17764 KB |
Output is correct |
36 |
Correct |
275 ms |
20672 KB |
Output is correct |
37 |
Correct |
204 ms |
21068 KB |
Output is correct |
38 |
Correct |
142 ms |
23968 KB |
Output is correct |
39 |
Correct |
101 ms |
26180 KB |
Output is correct |
40 |
Correct |
99 ms |
29516 KB |
Output is correct |
41 |
Correct |
418 ms |
32176 KB |
Output is correct |
42 |
Correct |
637 ms |
35664 KB |
Output is correct |
43 |
Correct |
339 ms |
38564 KB |
Output is correct |
44 |
Correct |
358 ms |
40992 KB |
Output is correct |
45 |
Correct |
177 ms |
43584 KB |
Output is correct |
46 |
Correct |
80 ms |
46348 KB |
Output is correct |
47 |
Correct |
76 ms |
48884 KB |
Output is correct |
48 |
Correct |
99 ms |
51788 KB |
Output is correct |
49 |
Correct |
94 ms |
54588 KB |
Output is correct |
50 |
Correct |
336 ms |
58520 KB |
Output is correct |
51 |
Correct |
80 ms |
60200 KB |
Output is correct |
52 |
Execution timed out |
5009 ms |
99812 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |