#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+5e4+5;
const ll inf=1e15;
const ll mod=1e9+7;
ll n;
ll x[maxn],y[maxn];
ii ranges[maxn];
vector<ll> pos;
vector<ii> updates;
ll fen[maxn];
void upd(ll x, ll v){
while (x<maxn){
fen[x]+=v;
x+=(x&-x);
}
}
ll query(ll x){
ll ans=0;
while (x){
ans+=fen[x];
x-=(x&-x);
}
return ans;
}
ll query(ll x, ll y){
return query(y)-query(x-1);
}
ll check(ll len){
vector<tuple<ll,ll,ll>> queries;
for (int i=1;i<=n;i++){
queries.emplace_back(y[i]-len-1,i,-1);
//exclusive
queries.emplace_back(y[i]+len,i,1);
//inclusive
ranges[i].first=lower_bound(pos.begin(),pos.end(),x[i]-len)
-pos.begin();
ranges[i].second=upper_bound(pos.begin(),pos.end(),x[i]+len)
-pos.begin()-1;
}
sort(queries.begin(),queries.end());
ll ans=0,ptr=0;
memset(fen,0,sizeof(fen));
for (auto [a,b,c]:queries){
while (ptr!=updates.size() &&
updates[ptr].first<=a){
upd(updates[ptr].second,1);
ptr++;
}
ans+=c*(query(ranges[b].first,ranges[b].second));
}
return (ans-n)/2;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll a,b,k;
cin>>n>>k;
assert(k==1);
for (int i=1;i<=n;i++){
cin>>a>>b;
x[i]=a+b,y[i]=a-b;
pos.emplace_back(x[i]);
}
pos.emplace_back(-inf);
sort(pos.begin(),pos.end());
pos.erase(unique(pos.begin(),pos.end()),pos.end());
for (int i=1;i<=n;i++){
ll res=lower_bound(pos.begin(),pos.end(),x[i])-pos.begin();
updates.emplace_back(y[i],res);
}
sort(updates.begin(),updates.end());
ll l=1,r=4'000'000'005,m;
while (l!=r-1){
m=(l+r)>>1;
if (check(m)) r=m;
else l=m;
}
cout<<r;
return 0;
}
Compilation message
road_construction.cpp: In function 'long long int check(long long int)':
road_construction.cpp:56:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while (ptr!=updates.size() &&
| ~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
4700 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
4700 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4267 ms |
40948 KB |
Output is correct |
2 |
Correct |
4384 ms |
40304 KB |
Output is correct |
3 |
Correct |
3 ms |
6744 KB |
Output is correct |
4 |
Correct |
4168 ms |
43724 KB |
Output is correct |
5 |
Correct |
3133 ms |
46404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4267 ms |
40948 KB |
Output is correct |
2 |
Correct |
4384 ms |
40304 KB |
Output is correct |
3 |
Correct |
3 ms |
6744 KB |
Output is correct |
4 |
Correct |
4168 ms |
43724 KB |
Output is correct |
5 |
Correct |
3133 ms |
46404 KB |
Output is correct |
6 |
Runtime error |
3 ms |
4700 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
4700 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
4700 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |