#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> curMax(k+1, 0);
vector<int> curIndex(k+1, 0);
vector<multiset<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) {
curMax[i] = max(curMax[i], S[i][curIndex[i]].b);
values[i].insert(S[i][curIndex[i]].x);
curIndex[i]++;
}
while(curRem[i] < (int)rem[i].size() and rem[i][curRem[i]].b < query.y) {
auto it = values[i].find(rem[i][curRem[i]].x);
values[i].erase(it);
curRem[i]++;
}
}
int inconvenience = 0;
for(int i = 1; i <= k; i++) {
int ina = +oo;
auto it = lower_bound(values[i].begin(), values[i].end(), query.l);
if(it != values[i].end()) {
ina = min(ina, abs(query.l - (*it)));
if(it != values[i].begin()) {
it--;
ina = min(ina, abs(query.l - (*it)));
}
}
if(values[i].size())
ina = min(ina, abs(query.l - (*values[i].rbegin())));
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 |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Correct |
3 ms |
560 KB |
Output is correct |
5 |
Correct |
4 ms |
560 KB |
Output is correct |
6 |
Correct |
5 ms |
572 KB |
Output is correct |
7 |
Correct |
7 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
716 KB |
Output is correct |
9 |
Correct |
8 ms |
716 KB |
Output is correct |
10 |
Correct |
6 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
724 KB |
Output is correct |
16 |
Correct |
8 ms |
724 KB |
Output is correct |
17 |
Correct |
5 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
724 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
8 ms |
724 KB |
Output is correct |
22 |
Correct |
8 ms |
848 KB |
Output is correct |
23 |
Correct |
6 ms |
848 KB |
Output is correct |
24 |
Correct |
5 ms |
848 KB |
Output is correct |
25 |
Correct |
4 ms |
848 KB |
Output is correct |
26 |
Correct |
4 ms |
848 KB |
Output is correct |
27 |
Correct |
4 ms |
848 KB |
Output is correct |
28 |
Correct |
4 ms |
848 KB |
Output is correct |
29 |
Correct |
4 ms |
848 KB |
Output is correct |
30 |
Correct |
4 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Correct |
3 ms |
560 KB |
Output is correct |
5 |
Correct |
4 ms |
560 KB |
Output is correct |
6 |
Correct |
5 ms |
572 KB |
Output is correct |
7 |
Correct |
7 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
716 KB |
Output is correct |
9 |
Correct |
8 ms |
716 KB |
Output is correct |
10 |
Correct |
6 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
724 KB |
Output is correct |
16 |
Correct |
8 ms |
724 KB |
Output is correct |
17 |
Correct |
5 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
724 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
8 ms |
724 KB |
Output is correct |
22 |
Correct |
8 ms |
848 KB |
Output is correct |
23 |
Correct |
6 ms |
848 KB |
Output is correct |
24 |
Correct |
5 ms |
848 KB |
Output is correct |
25 |
Correct |
4 ms |
848 KB |
Output is correct |
26 |
Correct |
4 ms |
848 KB |
Output is correct |
27 |
Correct |
4 ms |
848 KB |
Output is correct |
28 |
Correct |
4 ms |
848 KB |
Output is correct |
29 |
Correct |
4 ms |
848 KB |
Output is correct |
30 |
Correct |
4 ms |
848 KB |
Output is correct |
31 |
Execution timed out |
5075 ms |
7428 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5089 ms |
45304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5039 ms |
45304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Correct |
3 ms |
560 KB |
Output is correct |
5 |
Correct |
4 ms |
560 KB |
Output is correct |
6 |
Correct |
5 ms |
572 KB |
Output is correct |
7 |
Correct |
7 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
716 KB |
Output is correct |
9 |
Correct |
8 ms |
716 KB |
Output is correct |
10 |
Correct |
6 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
724 KB |
Output is correct |
16 |
Correct |
8 ms |
724 KB |
Output is correct |
17 |
Correct |
5 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
724 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
8 ms |
724 KB |
Output is correct |
22 |
Correct |
8 ms |
848 KB |
Output is correct |
23 |
Correct |
6 ms |
848 KB |
Output is correct |
24 |
Correct |
5 ms |
848 KB |
Output is correct |
25 |
Correct |
4 ms |
848 KB |
Output is correct |
26 |
Correct |
4 ms |
848 KB |
Output is correct |
27 |
Correct |
4 ms |
848 KB |
Output is correct |
28 |
Correct |
4 ms |
848 KB |
Output is correct |
29 |
Correct |
4 ms |
848 KB |
Output is correct |
30 |
Correct |
4 ms |
848 KB |
Output is correct |
31 |
Execution timed out |
5075 ms |
7428 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Correct |
3 ms |
560 KB |
Output is correct |
5 |
Correct |
4 ms |
560 KB |
Output is correct |
6 |
Correct |
5 ms |
572 KB |
Output is correct |
7 |
Correct |
7 ms |
716 KB |
Output is correct |
8 |
Correct |
6 ms |
716 KB |
Output is correct |
9 |
Correct |
8 ms |
716 KB |
Output is correct |
10 |
Correct |
6 ms |
716 KB |
Output is correct |
11 |
Correct |
3 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
3 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
724 KB |
Output is correct |
16 |
Correct |
8 ms |
724 KB |
Output is correct |
17 |
Correct |
5 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
724 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
8 ms |
724 KB |
Output is correct |
22 |
Correct |
8 ms |
848 KB |
Output is correct |
23 |
Correct |
6 ms |
848 KB |
Output is correct |
24 |
Correct |
5 ms |
848 KB |
Output is correct |
25 |
Correct |
4 ms |
848 KB |
Output is correct |
26 |
Correct |
4 ms |
848 KB |
Output is correct |
27 |
Correct |
4 ms |
848 KB |
Output is correct |
28 |
Correct |
4 ms |
848 KB |
Output is correct |
29 |
Correct |
4 ms |
848 KB |
Output is correct |
30 |
Correct |
4 ms |
848 KB |
Output is correct |
31 |
Execution timed out |
5075 ms |
7428 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |