CCCPaste

Untitled

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include 
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 10;
const ll INF = 3e16 + 10;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector> points(n);
    
    for(int i = 0; i < n; i++) {
        cin >> points[i].first >> points[i].second;
    }
    sort(points.begin(), points.end());
    set> st;
    st.insert(make_pair(points[0].first, points[0].second));
    ll shortest_distance = 1e9, result = 1e18;
    for(int i = 1; i < n; i++) {
        set>::iterator it1 = st.lower_bound(make_pair(points[i].first - shortest_distance, points[i].second - shortest_distance));
        
        set>::iterator it2 = st.upper_bound(make_pair(points[i].first, points[i].second + shortest_distance));
        
        if(it1 == st.end()) {
            continue;
        }
        
        for(set>::iterator it = it1; it != it2; it++) {
            ll dist = (points[i].first - it->first) * (points[i].first - it->first) + (points[i].second - it->second) * (points[i].second - it->second);
            result = min(result, dist);
        }
        st.insert(make_pair (points[i].first, points[i].second));
    }
    cout << sqrt(result) << endl;
    return 0;
}