Language: C++

#include <iostream>
#include <map>
#include <set>
using namespace std;

int N, a, b, d;
set<pair<int, int>> s1, s2, s3;

int getD(pair<int, int> z1, pair<int, int> z2) {
    return max(abs(z1.first - z2.first), abs(z1.second - z2.second));
}

void dfs(pair<int, int> z) {
    s3.insert(z);
    s1.erase(z);
    s2.erase(pair<int, int>(z.second, z.first));

    while (true) {
        auto itr1 = lower_bound(s1.begin(), s1.end(),
                                pair<int, int>(z.first - d, z.second - d));
        auto itr2 = upper_bound(s1.begin(), s1.end(),
                                pair<int, int>(z.first - d, z.second + d));
        if (itr1 == itr2) break;
        pair<int, int> p1 = *itr1;
        dfs(p1);
    }
    while (true) {
        auto itr1 = lower_bound(s1.begin(), s1.end(),
                                pair<int, int>(z.first + d, z.second - d));
        auto itr2 = upper_bound(s1.begin(), s1.end(),
                                pair<int, int>(z.first + d, z.second + d));
        if (itr1 == itr2) break;
        pair<int, int> p1 = *itr1;
        dfs(p1);
    }
    while (true) {
        auto itr1 = lower_bound(s2.begin(), s2.end(),
                                pair<int, int>(z.second - d, z.first - d));
        auto itr2 = upper_bound(s2.begin(), s2.end(),
                                pair<int, int>(z.second - d, z.first + d));
        if (itr1 == itr2) break;
        pair<int, int> p1 = pair<int, int>(itr1->second, itr1->first);
        dfs(p1);
    }
    while (true) {
        auto itr1 = lower_bound(s2.begin(), s2.end(),
                                pair<int, int>(z.second + d, z.first - d));
        auto itr2 = upper_bound(s2.begin(), s2.end(),
                                pair<int, int>(z.second + d, z.first + d));
        if (itr1 == itr2) break;
        pair<int, int> p1 = pair<int, int>(itr1->second, itr1->first);
        dfs(p1);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> a >> b;
    a--, b--;
    pair<int, int> za, zb;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        int x2 = x + y, y2 = x - y;
        if (i == a) za = pair<int, int>(x2, y2);
        if (i == b) zb = pair<int, int>(x2, y2);
        s1.insert(pair<int, int>(x2, y2));
        s2.insert(pair<int, int>(y2, x2));
    }
    d = getD(za, zb);

    dfs(za);
    if(s1.find(zb) != s1.end())
        dfs(zb);

    vector<pair<int, int>> v3, v4;
    for(auto z : s3){
        v3.push_back(z);
        v4.push_back(pair<int, int>(z.second, z.first));
    }
    sort(v3.begin(), v3.end());
    sort(v4.begin(), v4.end());
    int ans = 0;
    for(auto z : s3){
        ans += lower_bound(v3.begin(), v3.end(), pair<int, int>(z.first - d, z.second + d))
             - lower_bound(v3.begin(), v3.end(), pair<int, int>(z.first - d, z.second - d));
        ans += lower_bound(v3.begin(), v3.end(), pair<int, int>(z.first + d, z.second + d))
             - lower_bound(v3.begin(), v3.end(), pair<int, int>(z.first + d, z.second - d));
        ans += lower_bound(v4.begin(), v4.end(), pair<int, int>(z.second - d, z.first + d))
             - lower_bound(v4.begin(), v4.end(), pair<int, int>(z.second - d, z.first - d));
        ans += lower_bound(v4.begin(), v4.end(), pair<int, int>(z.second + d, z.first + d))
             - lower_bound(v4.begin(), v4.end(), pair<int, int>(z.second + d, z.first - d));
    }
    cout << ans / 2 << endl;
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(std::pair<int, int>)':
a.cc:21:21: error: 'upper_bound' was not declared in this scope
   21 |         auto itr2 = upper_bound(s1.begin(), s1.end(),
      |                     ^~~~~~~~~~~
a.cc:30:21: error: 'upper_bound' was not declared in this scope
   30 |         auto itr2 = upper_bound(s1.begin(), s1.end(),
      |                     ^~~~~~~~~~~
a.cc:39:21: error: 'upper_bound' was not declared in this scope
   39 |         auto itr2 = upper_bound(s2.begin(), s2.end(),
      |                     ^~~~~~~~~~~
a.cc:48:21: error: 'upper_bound' was not declared in this scope
   48 |         auto itr2 = upper_bound(s2.begin(), s2.end(),
      |                     ^~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:77:5: error: 'vector' was not declared in this scope
   77 |     vector<pair<int, int>> v3, v4;
      |     ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <set>
  +++ |+#include <vector>
    4 | using namespace std;
a.cc:77:25: error: expected primary-expression before '>' token
   77 |     vector<pair<int, int>> v3, v4;
      |                         ^~
a.cc:77:28: error: 'v3' was not declared in this scope; did you mean 's3'?
   77 |     vector<pair<int, int>> v3, v4;
      |                            ^~
      |                            s3
a.cc:77:32: error: 'v4' was not declared in this scope
   77 |     vector<pair<int, int>> v3, v4;
      |                                ^~
a.cc:82:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   82 |     sort(v3.begin(), v3.end());
      |     ^~~~
      |     short