#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) {
values[i].erase(rem[i][curRem[i]].x);
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 |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5012 ms |
44428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5092 ms |
44428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
444 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Incorrect |
5 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |