Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define inf 1000000007000000007
typedef long long ll;
using namespace std;

typedef pair<ll,ll> P;
set<P> datx,daty,setx,sety;
set<P>::iterator ita,itb;
queue<P> Q;
ll ans=0,k;

void BFS(ll x,ll y){
	
	ita=lower_bound(datx.begin(),datx.end(),make_pair(x-k,inf));
	itb=lower_bound(datx.begin(),datx.end(),make_pair(x-k,-inf));
	ans+=ita-itb;
	ita=lower_bound(setx.begin(),setx.end(),make_pair(x-k,-inf));
	while(ita<setx.end()){
		if(ita->first>x-k)break;
		Q.push(make_pair(ita->first,ita->second));
		setx.erase(make_pair(ita->first,ita->second));
		sety.erase(make_pair(ita->second,ita->first));
		ita++;
	}
	
	ita=lower_bound(datx.begin(),datx.end(),make_pair(x+k,inf));
	itb=lower_bound(datx.begin(),datx.end(),make_pair(x+k,-inf));
	ans+=ita-itb;
	ita=lower_bound(setx.begin(),setx.end(),make_pair(x+k,-inf));
	while(ita<setx.end()){
		if(ita->first>x+k)break;
		Q.push(make_pair(ita->first,ita->second));
		setx.erase(make_pair(ita->first,ita->second));
		sety.erase(make_pair(ita->second,ita->first));
		ita++;
	}
	
	ita=lower_bound(daty.begin(),daty.end(),make_pair(y-k,inf));
	itb=lower_bound(daty.begin(),daty.end(),make_pair(y-k,-inf));
	ans+=ita-itb;
	ita=lower_bound(sety.begin(),sety.end(),make_pair(y-k,-inf));
	while(ita<sety.end()){
		if(ita->first>y-k)break;
		Q.push(make_pair(ita->second,ita->first));
		setx.erase(make_pair(ita->second,ita->first));
		sety.erase(make_pair(ita->first,ita->second));
		ita++;
	}
	
	ita=lower_bound(daty.begin(),daty.end(),make_pair(y+k,inf));
	itb=lower_bound(daty.begin(),daty.end(),make_pair(y+k,-inf));
	ans+=ita-itb;
	ita=lower_bound(sety.begin(),sety.end(),make_pair(y+k,-inf));
	while(ita<sety.end()){
		if(ita->first>y+k)break;
		Q.push(make_pair(ita->second,ita->first));
		setx.erase(make_pair(ita->second,ita->first));
		sety.erase(make_pair(ita->first,ita->second));
		ita++;
	}
}

int main(){
	int n,f,g;
	cin>>n>>f>>g;f--,g--;
	ll sx,sy,gx,gy;
	lol(i,n){
		int x,y;cin>>x>>y;
		datx.insert(make_pair(x,y));
		daty.insert(make_pair(y,x));
		setx.insert(make_pair(x,y));
		sety.insert(make_pair(y,x));
		if(i==f){Q.push(make_pair(x,y));sx=x,sy=y;}
		if(j==g){Q.push(make_pair(x,y));gx=x,gy=y;}
	}
	k=abs(sx-gx)+abs(sy-gy);
	while(!Q.empty()){
		int x=Q.front.first;
		int y=Q.front.second;
		Q.pop();
		BFS(x,y);
	}
	cout<<ans/2<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'void BFS(ll, ll)':
a.cc:23:17: error: no match for 'operator-' (operand types are 'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} and 'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'})
   23 |         ans+=ita-itb;
      |              ~~~^~~~
      |              |   |
      |              |   _Rb_tree_const_iterator<[...]>
      |              _Rb_tree_const_iterator<[...]>
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:23:18: note:   'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} is not derived from 'const std::reverse_iterator<_Iterator>'
   23 |         ans+=ita-itb;
      |                  ^~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:23:18: note:   'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} is not derived from 'const std::move_iterator<_IteratorL>'
   23 |         ans+=ita-itb;
      |                  ^~~
In file included from a.cc:6:
/usr/include/c++/14/complex:370:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const complex<_Tp>&)'
  370 |     operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:370:5: note:   template argument deduction/substitution failed:
a.cc:23:18: note:   'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} is not derived from 'const std::complex<_Tp>'
   23 |         ans+=ita-itb;
      |                  ^~~
/usr/include/c++/14/complex:379:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const _Tp&)'
  379 |     operator-(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:379:5: note:   template argument deduction/substitution failed:
a.cc:23:18: note:   'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} is not derived from 'const std::complex<_Tp>'
   23 |         ans+=ita-itb;
      |                  ^~~
/usr/include/c++/14/complex:388:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const _Tp&, const complex<_Tp>&)'
  388 |     operator-(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:388:5: note:   template argument deduction/substitution failed:
a.cc:23:18: note:   'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} is not derived from 'const std::complex<_Tp>'
   23 |         ans+=ita-itb;
      |                  ^~~
/usr/include/c++/14/complex:465:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&)'
  465 |     operator-(const complex<_Tp>& __x)
      |     ^~~~~~~~
/usr/include/c++/14/complex:465:5: note:   candidate expects 1 argument, 2 provided
a.cc:25:18: error: no match for 'operator<' (operand types are 'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} and 'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'})
   25 |         while(ita<setx.end()){
      |               ~~~^~~~~~~~~~~
      |               |           |
      |               |           _Rb_tree_const_iterator<[...]>
      |               _Rb_tree_const_iterator<[...]>
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  448 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:448:5: note:   template argument deduction/substitution failed:
a.cc:25:28: note:   'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} is not derived from 'const std::reverse_iterator<_Iterator>'
   25 |         while(ita<setx.end()){
      |                            ^
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  493 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note:   template argument deduction/substitution failed:
a.cc:25:28: note:   'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} is not derived from 'const std::reverse_iterator<_Iterator>'
   25 |         while(ita<setx.end()){
      |                            ^
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1694 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note:   template argument deduction/substitution failed:
a.cc:25:28: note:   'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long int, long long int> >, std::less<std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, long long int> > >::const_iterator'} is not derived from 'const std::move_iterator<_IteratorL>'
   25 |         while(ita<setx.end()){
      |                            ^
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1760 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note:   template argument deduction/substitution failed:
a.cc:25:28: note:   'std::set<std::pair<long long int, long long int> >::iterator' {aka 'std::_Rb_tree<std::pair<long long int, long long int>, std::pair<long long int, long long int>, std::_Identity<std::pair<long long