This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int nax = 6e4 + 10;
int l[nax];
int x[nax], t[nax];
int pos[nax];
set<int>live[nax];
int ans[nax];
void PlayGround() {
int n, q, k;
cin>>n>>k>>q;
vector<int>imp;
map<int, vector<int>>query, shopin, shopout;
for(int i=0; i<n; ++i) {
cin>>x[i]>>t[i];
int a, b;
cin>>a>>b;
shopin[a].push_back(i);
shopout[b].push_back(i);
imp.push_back(a), imp.push_back(b);
}
for(int i=0; i<q; ++i) {
int x, y;
cin>>x>>y;
pos[i] = x;
query[y].push_back(i);
imp.push_back(y);
}
sort(imp.begin(), imp.end());
imp.resize(unique(imp.begin(), imp.end())-imp.begin());
for(int mom : imp) {
//cerr<<mom<<endl;
if(shopin.count(mom)) {
for(int j : shopin[mom]) {
live[t[j]].insert(x[j]);
}
}
if(query.count(mom)) {
for(int j : query[mom]) {
for(int i=1; i<=k; ++i) {
if(live[i].empty()) {
ans[j] = -1;
break;
}
int d1 = 1e9, d2 = 1e9;
auto it = live[i].lower_bound(pos[j]);
if(it!=live[i].end()) d1 = *it - pos[j];
if(it!=live[i].begin()) {
it = prev(it);
d2 = pos[j] - *it;
}
ans[j] = max(ans[j], min(d1, d2));
}
}
}
if(shopout.count(mom)) {
for(int j : shopout[mom]) {
live[t[j]].erase(x[j]);
}
}
}
for(int i=0; i<q; ++i) {
cout<<ans[i]<<'\n';
}
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |