Language: C++

#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef pair<double, int> PDI;
typedef vector<PDI> VD;

int n, a, b;
int x[100010], y[100010];
VI vxpyidx, vxmyidx;
int xpyidx[100010], xmyidx[100010];
VP xpy[100010], xmy[100010];

int dist;
queue<int> qu;
bool visited[100010];

int ans = 0;
signed main()
{
  scanf("%lld%lld%lld", &n, &a, &b);

  for(int i = 1; i <= n; i++){
    scanf("%lld%lld", &x[i], &y[i]);
    vxpyidx.PB(x[i] + y[i]);
    vxmyidx.PB(x[i] - y[i]);
  }

  sort(vxpyidx.begin(), vxpyidx.end());
  sort(vxmyidx.begin(), vxmyidx.end());
  vxpyidx.erase(unique(vxpyidx.begin(), vxpyidx.end()), vxpyidx.end());
  vxmyidx.erase(unique(vxmyidx.begin(), vxmyidx.end()), vxmyidx.end());

  for(int i = 1; i <= n; i++){
    xpyidx[i] = lower_bound(vxpyidx.begin(), vxpyidx.end(), x[i] + y[i]) - vxpyidx.begin();
    xmyidx[i] = lower_bound(vxmyidx.begin(), vxmyidx.end(), x[i] - y[i]) - vxmyidx.begin();
  }
  
  for(int i = 1; i <= n; i++){
    xpy[xpyidx[i]].PB(MP(x[i] - y[i], i));
    xmy[xmyidx[i]].PB(MP(x[i] + y[i], i));
  }

  for(int i = 0; i <= n; i++){
    sort(xpy[i].begin(), xpy[i].end());
    sort(xmy[i].begin(), xmy[i].end());
  }

  dist = abs(x[a] - x[b]) + abs(y[a] - y[b]);
  
  qu.push(a);
  qu.push(b);

  while(!qu.empty()){
    int now = qu.front();
    qu.pop();

    if(!visited[now]){
      visited[now] = true;
      
      {
	int idx = lower_bound(vxpyidx.begin(), vxpyidx.end(), x[now] + y[now] + dist) - vxpyidx.begin();

	if(vxpyidx[idx] == x[now] + y[now] + dist){
	  int st = lower_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] - dist, -INF)) - xpy.begin();
	  int ed = upper_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] + dist, INF)) - xpy.begin();

	  for(int i = st; i < ed; i++){
	    qu.push(xpy[i].S);
	    ans++;
	  }
	}

	int idx = lower_bound(vxpyidx.begin(), vxpyidx.end(), x[now] + y[now] - dist) - vxpyidx.begin();

	if(vxpyidx[idx] == x[now] + y[now] - dist){
	  int st = lower_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] - dist, -INF)) - xpy.begin();
	  int ed = upper_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] + dist, INF)) - xpy.begin();

	  for(int i = st; i < ed; i++){
	    qu.push(xpy[i].S);
	    ans++;
	  }
	}
      }

      {
	int idx = lower_bound(vxmyidx.begin(), vxmyidx.end(), x[now] - y[now] + dist) - vxmyidx.begin();

	if(vxmyidx[idx] == x[now] - y[now] + dist){
	  int st = lower_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] - dist, -INF)) - xmy.begin();
	  int ed = upper_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] + dist, INF)) - xmy.begin();

	  for(int i = st; i < ed; i++){
	    qu.push(xmy[i].S);
	    ans++;
	  }
	}

	int idx = lower_bound(vxmyidx.begin(), vxmyidx.end(), x[now] - y[now] - dist) - vxmyidx.begin();

	if(vxmyidx[idx] == x[now] - y[now] - dist){
	  int st = lower_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] - dist, -INF)) - xmy.begin();
	  int ed = upper_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] + dist, INF)) - xmy.begin();

	  for(int i = st; i < ed; i++){
	    qu.push(xmy[i].S);
	    ans++;
	  }
	}
      }
    }
  }

  printf("%lld\n", ans / 2);
  
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:71:36: error: 'i' was not declared in this scope
   71 |           int st = lower_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] - dist, -INF)) - xpy.begin();
      |                                    ^
a.cc:71:90: error: 'INF' was not declared in this scope
   71 |           int st = lower_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] - dist, -INF)) - xpy.begin();
      |                                                                                          ^~~
a.cc:71:102: error: request for member 'begin' in 'xpy', which is of non-class type 'VP [100010]' {aka 'std::vector<std::pair<long long int, long long int> > [100010]'}
   71 |           int st = lower_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] - dist, -INF)) - xpy.begin();
      |                                                                                                      ^~~~~
a.cc:72:101: error: request for member 'begin' in 'xpy', which is of non-class type 'VP [100010]' {aka 'std::vector<std::pair<long long int, long long int> > [100010]'}
   72 |           int ed = upper_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] + dist, INF)) - xpy.begin();
      |                                                                                                     ^~~~~
a.cc:6:11: error: 'VP' {aka 'class std::vector<std::pair<long long int, long long int> >'} has no member named 'second'
    6 | #define S second
      |           ^~~~~~
a.cc:75:28: note: in expansion of macro 'S'
   75 |             qu.push(xpy[i].S);
      |                            ^
a.cc:80:13: error: redeclaration of 'long long int idx'
   80 |         int idx = lower_bound(vxpyidx.begin(), vxpyidx.end(), x[now] + y[now] - dist) - vxpyidx.begin();
      |             ^~~
a.cc:68:13: note: 'long long int idx' previously declared here
   68 |         int idx = lower_bound(vxpyidx.begin(), vxpyidx.end(), x[now] + y[now] + dist) - vxpyidx.begin();
      |             ^~~
a.cc:83:36: error: 'i' was not declared in this scope
   83 |           int st = lower_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] - dist, -INF)) - xpy.begin();
      |                                    ^
a.cc:83:90: error: 'INF' was not declared in this scope
   83 |           int st = lower_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] - dist, -INF)) - xpy.begin();
      |                                                                                          ^~~
a.cc:83:102: error: request for member 'begin' in 'xpy', which is of non-class type 'VP [100010]' {aka 'std::vector<std::pair<long long int, long long int> > [100010]'}
   83 |           int st = lower_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] - dist, -INF)) - xpy.begin();
      |                                                                                                      ^~~~~
a.cc:84:101: error: request for member 'begin' in 'xpy', which is of non-class type 'VP [100010]' {aka 'std::vector<std::pair<long long int, long long int> > [100010]'}
   84 |           int ed = upper_bound(xpy[i].begin(), xpy[i].end(), MP(x[now] - y[now] + dist, INF)) - xpy.begin();
      |                                                                                                     ^~~~~
a.cc:6:11: error: 'VP' {aka 'class std::vector<std::pair<long long int, long long int> >'} has no member named 'second'
    6 | #define S second
      |           ^~~~~~
a.cc:87:28: note: in expansion of macro 'S'
   87 |             qu.push(xpy[i].S);
      |                            ^
a.cc:97:36: error: 'i' was not declared in this scope
   97 |           int st = lower_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] - dist, -INF)) - xmy.begin();
      |                                    ^
a.cc:97:90: error: 'INF' was not declared in this scope
   97 |           int st = lower_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] - dist, -INF)) - xmy.begin();
      |                                                                                          ^~~
a.cc:97:102: error: request for member 'begin' in 'xmy', which is of non-class type 'VP [100010]' {aka 'std::vector<std::pair<long long int, long long int> > [100010]'}
   97 |           int st = lower_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] - dist, -INF)) - xmy.begin();
      |                                                                                                      ^~~~~
a.cc:98:101: error: request for member 'begin' in 'xmy', which is of non-class type 'VP [100010]' {aka 'std::vector<std::pair<long long int, long long int> > [100010]'}
   98 |           int ed = upper_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] + dist, INF)) - xmy.begin();
      |                                                                                                     ^~~~~
a.cc:6:11: error: 'VP' {aka 'class std::vector<std::pair<long long int, long long int> >'} has no member named 'second'
    6 | #define S second
      |           ^~~~~~
a.cc:101:28: note: in expansion of macro 'S'
  101 |             qu.push(xmy[i].S);
      |                            ^
a.cc:106:13: error: redeclaration of 'long long int idx'
  106 |         int idx = lower_bound(vxmyidx.begin(), vxmyidx.end(), x[now] - y[now] - dist) - vxmyidx.begin();
      |             ^~~
a.cc:94:13: note: 'long long int idx' previously declared here
   94 |         int idx = lower_bound(vxmyidx.begin(), vxmyidx.end(), x[now] - y[now] + dist) - vxmyidx.begin();
      |             ^~~
a.cc:109:36: error: 'i' was not declared in this scope
  109 |           int st = lower_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] - dist, -INF)) - xmy.begin();
      |                                    ^
a.cc:109:90: error: 'INF' was not declared in this scope
  109 |           int st = lower_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] - dist, -INF)) - xmy.begin();
      |                                                                                          ^~~
a.cc:109:102: error: request for member 'begin' in 'xmy', which is of non-class type 'VP [100010]' {aka 'std::vector<std::pair<long long int, long long int> > [100010]'}
  109 |           int st = lower_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] - dist, -INF)) - xmy.begin();
      |                                                                                                      ^~~~~
a.cc:110:101: error: request for member 'begin' in 'xmy', which is of non-class type 'VP [100010]' {aka 'std::vector<std::pair<long long int, long long int> > [100010]'}
  110 |           int ed = upper_bound(xmy[i].begin(), xmy[i].end(), MP(x[now] + y[now] + dist, INF)) - xmy.begin();
      |                                                                                                     ^~~~~
a.cc:6:11: error: 'VP' {aka 'class std::vector<std::pair<long long int, long long int> >'} has no member named 'second'
    6 | #define S second
      |           ^~~~~~
a.cc:113:28: note: in expansion of macro 'S'
  113 |             qu.push(xmy[i].S);
      |                            ^