Yahbim @ 2022-05-05 17:46:20
WA 了前两个小数据点(#2#3)和三个较大的,然而对拍拍了几千组没拍出 WA
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll INFLL=0x3f3f3f3f3f3f3f3f;
const int N=4e5+5;
namespace IO{
template<class type> type read(type ret=0,int w=0,char ch=getchar()){
while(!isdigit(ch)) w=ch=='-',ch=getchar();
while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar();
return w?-ret:ret;
}
template<class type> void write(type x){
if(x<0) return putchar('-'),write(-x);
if(x>9) write(x/10);
putchar('0'+x%10);
}
template<class type> void write_s(type x){write(x),putchar(' ');}
template<class type> void write_n(type x){write(x),putchar('\n');}
}using namespace IO;
int n;ll ans=INFLL;
struct node{int x,y;}p[N];
inline ll squa(int x){return 1ll*x*x;}
inline ll getdis(node a,node b){return squa(a.x-b.x)+squa(a.y-b.y);}
void solve(int l,int r){
if(l==r) return;
static basic_string<node> s,t;
int mid=(l+r)>>1,llim=0,rlim=INF;
solve(l,mid),solve(mid+1,r),s.clear(),t.clear();
for(int i=l;i<=mid;++i) llim=max(llim,p[i].x);
for(int i=mid+1;i<=r;++i) rlim=min(rlim,p[i].x);
for(int i=l;i<=mid;++i)
if(squa(llim-p[i].x)<ans) s.push_back(p[i]);
for(int i=mid+1;i<=r;++i)
if(squa(p[i].x-rlim)<ans) t.push_back(p[i]);
for(auto i=s.begin(),l=t.begin(),r=t.begin();i!=s.end();++i){
while(r!=t.end()&&((*r).y<=(*i).y||squa((*r).y-(*i).y)<ans)) ++r;
while(l!=r&&squa((*l).y-(*i).y)>=ans) ++l;
for(auto tmp=l;tmp!=r;++tmp) ans=min(ans,getdis(*i,*tmp));
}
inplace_merge(p+l,p+mid+1,p+r+1,[=](node a,node b){return a.y<b.y;});
}
signed main(){
n=read<int>();
for(int i=1;i<=n;++i) p[i]={read<int>(),read<int>()};
sort(p+1,p+1+n,[=](node a,node b){return a.x<b.x;});
solve(1,n);
write_n(ans);
return 0;
}
//~kawaii~
by E1_de5truct0r @ 2022-05-05 18:17:21
其实您用带一点技巧的暴力就可以过()
by Yahbim @ 2022-05-05 19:18:57
原因找到了,无穷小设成 0 而不是 -INF 了