This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
//#define mp make_pair
#define mid (l+r)/2
#define le node * 2
#define ri node * 2 + 1
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
#define gc getchar_unlocked
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef pair<double,ll>pdi;
const ll inf=1e18;
const ll mod=987654321;
const ld Pi=acos(-1);
int n , k , q ;
int x [400009] , t [400009] , l [400009] , r [400009] ;
pair < pi , int > que [400009] ;
int ANS [400009] ;
map < int , int > mp ;
vi in [400009] , out [400009] , query [400009] ;
multiset < int > s [400009] ;
int main () {
cin >> n >> k >> q ;
set < int > st ;
for ( int i = 0 ; i < n ; i ++ ) {
cin >> x [i] >> t [i] >> l [i] >> r [i] ;
st .ins ( l [i] ) ;
st .ins ( r [i] ) ;
}
for ( int i = 0 ; i < q ; i ++ ) {
cin >> que [i] .fi.se >> que [i] .fi.fi ;
que [i] .se = i ;
st .ins ( que [i] .fi.fi ) ;
}
sort ( que , que + q ) ;
int N = 0 ;
for ( auto u : st ) mp [u] = N ++ ;
for ( int i = 0 ; i < n ; i ++ ) {
l [i] = mp [l[i]] ;
r [i] = mp [r[i]] ;
in [l[i]] .pb ( i ) ;
out[r[i]] .pb ( i ) ;
}
for ( int i = 0 ; i < q ; i ++ ) {
que [i] .fi.fi = mp [ que [i] .fi.fi ] ;
query [ que [i] .fi.fi ] .pb ( i ) ;
}
/* for ( int i = 0 ; i < n ; i ++ ) {
cout << x [i] << " " << t [i] << " " << l [i] << " " << r [i] << endl ;
}
cout << endl ;
for ( int i = 0 ; i < q ; i ++ ) {
cout << que [i] .fi.fi << endl ;
}
cout << endl ;
cout << N << endl ;
*/
for ( int i = 0 ; i < N ; i ++ ) {
for ( auto u : in [i] ) {
s [t[u]] .ins ( x [u] ) ;
// cout << u << " " ;
}
// cout << " || " ;
for ( auto u : query [i] ) {
int loc = que [u] .fi.se , id = que [u] .se , ans = 0 ;
// cout << id << " " ;
for ( int j = 1 ; j <= k ; j ++ ) {
int crnt = 1e9 ;
auto af = s [j] .lb ( loc ) ;
if ( af != s [j] .end () ) {
crnt = min ( crnt , abs ( *af - loc ) ) ;
}
auto bf = s [j] .ub ( loc ) ;
if ( bf != s [j] .begin () ) {
bf -- ;
crnt = min ( crnt , abs ( *bf - loc ) ) ;
}
ans = max ( ans , crnt ) ;
}
ANS [id] = ( ans == 1e9 ? -1 : ans ) ;
}
// cout << " || " ;
for ( auto u : out [i] ) {
s [t[u]] .era ( s[t[u]].find (x [u]) ) ;
// cout << u << " " ;
}
// cout << endl ;
}
for ( int i = 0 ; i < q ; i ++ ) cout << ANS [i] << endl ;
}
# | 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... |