Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll n;
ll ans;
ll x[100000], y[100000];
ll dx[4] = {1, 1, -1, -1}, dy[4] = {1, -1, 1, -1};
int a, b;
ll dis;
map<P, int> brd;
map<ll, vector<P>> mx;
map<ll, vector<P>> my;
set<ll> sx, sy;
int tox[100000], toy[100000];
bool done[100000];
vector<P> mx[10000];

bool cmp(P l, P r) {
    return l.first < r.first;
}

int main(){
    memset(tox, -1, sizeof(tox));
    memset(toy, -1, sizeof(toy));
    cin >> n >> a >> b;
    rep(i,n) cin >> x[i] >> y[i];
    a--; b--;
    rep(i,n) {
        ll tmp = x[i]+y[i];
        y[i] = x[i]-y[i];
        x[i] = tmp;
        mx[x[i]].push_back(P(y[i],i));
        my[y[i]].push_back(P(x[i],i));
        brd[P(x[i],y[i])] = i;
        //cout << x[i] << " " << y[i] << endl;
    }
    dis = max(abs(x[a]-x[b]), abs(y[a]-y[b]));
    //cout << dis << endl;
    rep(i,n) {
        if (!sx.count(x[i])) {
            vector<P> tmp = mx[x[i]];
            sort(tmp.begin(), tmp.end());
            mx[x[i]] = tmp;
            sx.insert(x[i]);
        }
        if (!sy.count(y[i])) {
            vector<P> tmp = my[y[i]];
            sort(tmp.begin(), tmp.end());
            my[y[i]] = tmp;
            sy.insert(y[i]);
        }
    }
    vector<ll> p; p.push_back(a); p.push_back(b);
    done[a] = true; done[b] = true;
    rep(i,p.size()) {
        ll px = x[p[i]], py = y[p[i]];
        rep(j,4) {
            if (brd.count(P(px+dx[j]*dis, py+dy[j]*dis))) {
                int tmp = brd[P(px+dx[j]*dis,py+dy[j]*dis)];
                ans++;
                if (!done[tmp]) {
                    done[tmp] = true;
                    p.push_back(tmp);
                }
            }
        }
        vector<P>::iterator st, en;
        //rep(j,mx[px+dis].size()) cout << "P(" << mx[px+dis][j].first << "," << mx[px+dis][j].second << ") ";
        //cout << endl;
        //cout << "p " << py-dis+1 << " " << py+dis-1 << endl;
        st = lower_bound(mx[px+dis].begin(), mx[px+dis].end(), P(py-dis+1,-1));
        en = lower_bound(mx[px+dis].begin(), mx[px+dis].end(), P(py+dis,-1));
        int sst = st-mx[px+dis].begin(), een = en-mx[px+dis].begin();
        //cout << sst << " " << een << endl;
        for (int j = sst; j < een; j++) {
            int k = mx[px+dis][j].second;
            if (!done[k]) {
                done[k] = true;
                p.push_back(k);
            }
            if (tox[k] == -1) tox[k] = een-1;
            else {
                if (tox[tox[k]] > 0) j = tox[tox[k]];
                else j = tox[k];
            }
        }
        ans += een-sst;
        //rep(j,mx[px-dis].size()) cout << "P(" << mx[px-dis][j].first << "," << mx[px-dis][j].second << ") ";
        //cout << endl;
        //cout << "p " << py-dis+1 << " " << py+dis-1 << endl;
        st = lower_bound(mx[px-dis].begin(), mx[px-dis].end(), P(py-dis+1,-1));
        en = lower_bound(mx[px-dis].begin(), mx[px-dis].end(), P(py+dis,-1));
        sst = st-mx[px-dis].begin(), een = en-mx[px-dis].begin();
        //cout << sst << " " << een << endl;
        for (int j = sst; j < een; j++) {
            int k = mx[px-dis][j].second;
            if (!done[k]) {
                done[k] = true;
                p.push_back(k);
            }
            if (tox[k] == -1) tox[k] = een-1;
            else {
                if (tox[tox[k]] > 0) j = tox[tox[k]];
                else j = tox[k];
            }
        }
        ans += een-sst;
        //rep(j,my[py+dis].size()) cout << "P(" << my[py+dis][j].first << "," << my[py+dis][j].second << ") ";
        //cout << endl;
        //cout << "p " << px-dis+1 << " " << px+dis-1 << endl;
        st = lower_bound(my[py+dis].begin(), my[py+dis].end(), P(px-dis+1,-1));
        en = lower_bound(my[py+dis].begin(), my[py+dis].end(), P(px+dis,-1));
        sst = st-my[py+dis].begin(), een = en-my[py+dis].begin();
        //cout << sst << " " << een << endl;
        for (int j = sst; j < een; j++) {
            int k = my[py+dis][j].second;
            if (!done[k]) {
                done[k] = true;
                p.push_back(k);
            }
            if (toy[k] == -1) toy[k] = een-1;
            else {
                if (toy[toy[k]] > 0) j = toy[toy[k]];
                else j = toy[k];
            }
        }
        ans += een-sst;
        //rep(j,my[py-dis].size()) cout << "P(" << my[py-dis][j].first << " " << my[py-dis][j].second << ") ";
        //cout << endl;
        //cout << "p " << px-dis+1 << " " << px+dis-1 << endl;
        st = lower_bound(my[py-dis].begin(), my[py-dis].end(), P(px-dis+1,-1));
        en = lower_bound(my[py-dis].begin(), my[py-dis].end(), P(px+dis,-1));
        sst = st-my[py-dis].begin(), een = en-my[py-dis].begin();
        //cout << sst << " " << een << endl;
        for (int j = sst; j < een; j++) {
            int k = my[py-dis][j].second;
            if (!done[k]) {
                done[k] = true;
                p.push_back(k);
            }
            if (toy[k] == -1) toy[k] = een-1;
            else {
                if (toy[toy[k]] > 0) j = toy[toy[k]];
                else j = toy[k];
            }
        }
        ans += een-sst;
    }
    cout << ans/2 << endl;
}
































Compiler output:
a.cc:23:11: error: conflicting declaration 'std::vector<std::pair<long long int, long long int> > mx [10000]'
   23 | vector<P> mx[10000];
      |           ^~
a.cc:18:20: note: previous declaration as 'std::map<long long int, std::vector<std::pair<long long int, long long int> > > mx'
   18 | map<ll, vector<P>> mx;
      |                    ^~