F - Dist Max
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 500500 points
Problem Statement
Given are NN distinct points in a two-dimensional plane. Point ii (1 \leq i \leq N)(1≤i≤N) has the coordinates (x_i,y_i)(xi,yi).
Let us define the distance between two points ii and jj be \mathrm{min} (|x_i-x_j|,|y_i-y_j|)min(∣xi−xj∣,∣yi−yj∣): the smaller of the difference in the xx-coordinates and the difference in the yy-coordinates.
Find the maximum distance between two different points.
Constraints
- 2 \leq N \leq 2000002≤N≤200000
- 0 \leq x_i,y_i \leq 10^90≤xi,yi≤109
- (x_i,y_i)(xi,yi) \neq= (x_j,y_j)(xj,yj) (i \neq j)(i=j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
NN x_1x1 y_1y1 x_2x2 y_2y2 \vdots⋮ x_NxN y_NyN
Output
Print the maximum distance between two different points.
Sample Input 1 Copy
Copy
3 0 3 3 1 4 10
Sample Output 1 Copy
Copy
4
The distances between Points 11 and 22, between Points 11 and 33, and between Points 22 and 33 are 22, 44, and 11, respectively, so your output should be 44.
Sample Input 2 Copy
Copy
4 0 1 0 4 0 10 0 6
Sample Output 2 Copy
Copy
0
Sample Input 3 Copy
Copy
8 897 729 802 969 765 184 992 887 1 104 521 641 220 909 380 378
Sample Output 3 Copy
Copy
801
答案的单调性就是指 有很多方案 每个方案有对应的最小值 求所有方案的最大值 比最大值小的方案就能实现 所以就是单调的 然后给定一个答案判断合不合法然后构造满足答案的方案 然后这个题是二维的坐标点 所以先按x排序消掉一维 然后现在是二分答案mid 然后我们就要往后找点匹配 所以就是判断当前的xi+mid之后的点 然后维护集合里y的最大值最小值
/*Where there is light, in my heart.*/
/*SUMMER_TRAINING DAY 16*/
#include<bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
//
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f
#define ll long long
//#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define unmap(a,b) unordered_map<a,b>
#define unset(a) unordered_set<a>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _rep(i, a, b) for (int i = (a); i >= (b); --i)
#define mode 1e4+7
#define pi acos(-1)
typedef double db;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> vi;
const int N=2e5+5;
//
PII a[N];
int n;
//
bool check(int mid){
int minn=1e9,maxx=0;
for(int i=1,j=1;i<=n;i++){
while(j<=n&&a[i].F>=a[j].F+mid){
minn=min(minn,a[j].S);
maxx=max(maxx,a[j].S);
j++;
}
if(a[i].S<=maxx-mid||a[i].S>=minn+mid) return true;
}
return false;
}
//
signed main(){
IOS;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i].F>>a[i].S;
sort(a+1,a+1+n);
int l=0,r=1e9;
while(l<r){
int mid=l+r+1>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<r<<endl;
}
//made by shun 20220719