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;
#define ll long long
#define ii pair<ll,ll>
#define iii tuple<ll,ll,ll>
#ifndef DEBUG
#define cerr if (0) cerr
#define endl '\n'
#endif // DEBUG
const ll maxn=2e5+5;
const ll inf=1e15;
const ll mod=1e9+7;
multiset<ll> s[405];
vector<tuple<ll,ll,ll,ll>> v;
vector<iii> q;
ll ans[maxn];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,qu,x,t,a,b,k;
cin>>n>>k>>qu;
for (int i=1;i<=n;i++){
cin>>x>>t>>a>>b;
v.emplace_back(a,x,t,1);
v.emplace_back(b+1,x,t,-1);
}
sort(v.begin(),v.end());
for (int i=1;i<=qu;i++){
cin>>x>>t;
q.emplace_back(t,x,i);
}
sort(q.begin(),q.end());
for (int i=1;i<=k;i++) s[i].emplace(-inf),s[i].emplace(inf);
ll ptr=0;
for (auto [t,x,idx]:q){
while (ptr!=v.size() && get<0>(v[ptr])<=t){
ll a,b,c,d;
tie(a,b,c,d)=v[ptr];
if (d==-1){
s[c].erase(s[c].find(b));
} else{
s[c].emplace(b);
}
ptr++;
}
ll tot=0;
for (int i=1;i<=k;i++){
auto it=s[i].lower_bound(x);
auto it2=it;
it2--;
ll dis=min(abs(x-*it),abs(x-*it2));
tot=max(dis,tot);
}
if (tot>mod) ans[idx]=-1;
else ans[idx]=tot;
}
for (int i=1;i<=qu;i++) cout<<ans[i]<<endl;
return 0;
}
Compilation message (stderr)
new_home.cpp: In function 'int main()':
new_home.cpp:40:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | while (ptr!=v.size() && get<0>(v[ptr])<=t){
| ~~~^~~~~~~~~~
# | 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... |