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 <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 6e4 + 10;
int x[N], t[N], a[N], b[N], l[N], y[N], Ans[N];
multiset<int> loc[405];
int main(){
int n,k,q;
cin>>n>>k>>q;
vector<pair<int,int>> tm;
for (int i=1;i<=n;i++){
cin>>x[i]>>t[i]>>a[i]>>b[i];
tm.push_back({a[i],i});
}
sort(begin(tm),end(tm));
vector<pair<int,int>> Q;
for (int i=1;i<=q;i++){
cin>>l[i]>>y[i];
Q.push_back({y[i],i});
}
sort(begin(Q),end(Q));
int tmi = 0;
set<pair<int,int>> ert;
for (auto [year,ind] : Q){
while (tmi < n and tm[tmi].first <= year){
int I = tm[tmi].second;
tmi++;
ert.insert({b[I],I});
loc[t[I]].insert(x[I]);
}
while (ert.size() > 0 and (*begin(ert)).first < year){
int I = (*begin(ert)).second;
ert.erase(begin(ert));
loc[t[I]].erase(loc[t[I]].find(x[I]));
}
int ans = 0;
for (int i=1;i<=k;i++){
if (loc[i].size() == 0){
ans = -1;
break;
}
int nans = 1e9;
auto u = loc[i].upper_bound(l[ind]-1);
if (u != loc[i].end())
nans = min(nans,*u - l[ind]);
if (u != loc[i].begin())
nans = min(nans,l[ind] - *prev(u));
ans = max(ans,nans);
}
Ans[ind] = ans;
}
for (int i=1;i<=q;i++)
cout<<Ans[i]<<'\n';
}
# | 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... |