#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][S[i][curRem[i]].x]--;
auto it = values[i].find(S[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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5082 ms |
44408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5100 ms |
44408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |