Language: C++

#include<bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define rhl (1000000007)
#define N (1000005)
#define lower_bound lb
using namespace std;

struct data{
	int x,y;
}a[35];
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int cnt[65][65],can[65][65],dis[65][65],ans;
int sx[N],sy[N],covx[N],covy[N],n,m,k,lx,ly;
queue<pair<int,int> > Q;
vector<int> px,py;

il int gi(){
	RG int x=0;RG char ch=getchar();
	RG bool q=1;
	while((ch<'0'||ch>'9')&& ch!='-')
	ch=getchar();
	if (ch=='-')q=!q,ch=getchar();
	while(ch>='0'&&ch<='9')
	x=x*10+ch-'0',ch=getchar();
	return (q)?x:-x;;
}

il void bfs(RG int sx,RG int sy){
	memset(dis,0,sizeof(dis));
	dis[sx][sy]=1,Q.push(make_pair(sx,sy));
	while(!Q.empty()){
		pair<int,int>now=Q.front();
		Q.pop();
		for(RG int i=0,x,y;i<4;++i){
			int a=now.first,b=now.second;
			x=a+dx[i];
			y=b+dy[i];
			if(x<0||x>lx||y<0||y>ly||
			dis[x][y]||can[x][y])continue;
			dis[x][y]=dis[a][b]+1;
			Q.push(make_pair(x,y));
			int c=1LL*cnt[sx][sy]*cnt[x][y];
			ans+=c%rhl*(dis[x][y]-1))%rhl;
		}
	}
	return;
}

int main(){
	n=gi(),m=gi(),k=gi();
	px.push_back(1),px.push_back(n+1);
	py.push_back(1),py.push_back(m+1);
	for(RG int i=1;i<=n;++i)sx[i]=m;
	for(RG int i=1;i<=m;++i)sy[i]=n;
	for(RG int i=1;i<=k;++i){
		px.push_back(a[i].x=gi()+1);
		px.push_back(a[i].x+1);
		py.push_back(a[i].y=gi()+1);
		py.push_back(a[i].y+1);
		--sx[a[i].x],--sy[a[i].y];
		covx[a[i].x]=covy[a[i].y]=1;
	}
	for(RG int i=1;i<=n;++i)
	(sx[i]+=sx[i-1])%=rhl;
	for(RG int i=1;i<=m;++i)
	(sy[i]+=sy[i-1])%=rhl;
	for (RG int i=1;i<n;++i)
	if(!covx[i]&&!covx[i+1])
	ans=(ans+2LL*sx[i]*(sx[n]-sx[i]))%rhl;
	for (RG int i=1;i<m;++i)
	if(!covy[i]&&!covy[i+1])
	ans=(ans+2LL*sy[i]*(sy[m]-sy[i]))%rhl;
	int*it1=px.end(),*it2=py.end();
	sort(px.begin(),it1);
	px.erase(unique(px.begin(),it1);it1);
	lx=px.size()-2;
	sort(py.begin(),it2);
	py.erase(unique(py.begin(),it2),it2);
	ly=py.size()-2;
	for (RG int i=1;i<=k;++i){
		a[i].x=lb(px.begin(),it1,a[i].x);
		a[i].x-=px.begin();
		a[i].y=lb(py.begin(),it2,a[i].y);
		a[i].y-=py.begin();
		can[a[i].x][a[i].y]=1;
	}
	for(RG int i=0;i<=lx;++i){
		for(RG int j=0;j<=ly;++j){
			int x=px[i+1]-px[i];
			int y=py[j+1]-py[j];
			cnt[i][j]=1LL*x*y%rhl;
		}
	}
	for(RG int i=0;i<=lx;++i){
		for(RG int j=0;j<=ly;++j){
			if(!can[i][j])bfs(i,j);
		}
	}
	cout<<1LL*(ans+rhl)*(rhl/2+1)%rhl<<"\n";
	return 0;
}

Compiler output:
a.cc: In function 'int gi()':
a.cc:20:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   20 |         RG int x=0;RG char ch=getchar();
      |                ^
a.cc:20:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   20 |         RG int x=0;RG char ch=getchar();
      |                            ^~
a.cc:21:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   21 |         RG bool q=1;
      |                 ^
a.cc: At global scope:
a.cc:30:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   30 | il void bfs(RG int sx,RG int sy){
      |                    ^~
a.cc:30:30: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   30 | il void bfs(RG int sx,RG int sy){
      |                              ^~
a.cc: In function 'void bfs(int, int)':
a.cc:36:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   36 |                 for(RG int i=0,x,y;i<4;++i){
      |                            ^
a.cc:36:32: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   36 |                 for(RG int i=0,x,y;i<4;++i){
      |                                ^
a.cc:36:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   36 |                 for(RG int i=0,x,y;i<4;++i){
      |                                  ^
a.cc:45:49: error: expected ';' before ')' token
   45 |                         ans+=c%rhl*(dis[x][y]-1))%rhl;
      |                                                 ^
      |                                                 ;
a.cc: In function 'int main()':
a.cc:55:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   55 |         for(RG int i=1;i<=n;++i)sx[i]=m;
      |                    ^
a.cc:56:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   56 |         for(RG int i=1;i<=m;++i)sy[i]=n;
      |                    ^
a.cc:57:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   57 |         for(RG int i=1;i<=k;++i){
      |                    ^
a.cc:65:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   65 |         for(RG int i=1;i<=n;++i)
      |                    ^
a.cc:67:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   67 |         for(RG int i=1;i<=m;++i)
      |                    ^
a.cc:69:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   69 |         for (RG int i=1;i<n;++i)
      |                     ^
a.cc:72:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   72 |         for (RG int i=1;i<m;++i)
      |                     ^
a.cc:75:23: error: cannot convert 'std::vector<int>::iterator' to 'int*' in initialization
   75 |         int*it1=px.end(),*it2=py.end();
      |                 ~~~~~~^~
      |                       |
      |                       std::vector<int>::iterator
a.cc:75:37: error: cannot convert 'std::vector<int>::iterator' to 'int*' in initialization
   75 |         int*it1=px.end(),*it2=py.end();
      |                               ~~~~~~^~
      |                                     |
      |                                     std::vector<int>::iterator
a.cc:76:13: error: no matching function for call to 'sort(std::vector<int>::iterator, int*&)'
   76 |         sort(px.begin(),it1);
      |         ~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4762:5: note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:5: note:   template argument deduction/substitution failed:
a.cc:76:13: note:   deduced conflicting types for parameter '_RAIter' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int*')
   76 |         sort(px.begin(),it1);
      |         ~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   candidate expects 3 arguments, 2 provided
a.cc:77:24: error: no matching function for call to 'unique(std::vector<int>::iterator, int*&)'
   77 |         px.erase(unique(px.begin(),it1);it1);
      |                  ~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:891:5: note: candidate: 'template<class _FIter> _FIter std::unique(_FIter, _FIter)'
  891 |     unique(_ForwardIterator __first, _ForwardIterator __last)
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:891:5: note:   template argument deduction/substitution failed:
a.cc:77:24: note:   deduced conflicting types for parameter '_FIter' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int*')
   77 |         px.erase(unique(px.begin(),it1);it1);
      |                  ~~~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:922:5: note: candidate: 'template<class _FIter, class _BinaryPredicate> _FIter std::unique(_FIter, _FIter, _BinaryPredicate)'
  922 |     unique(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:922:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:230:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::unique(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _BinaryPredicate)'
  230 | unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred);
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:230:1: note:   candidate expects 4 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:234:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::unique(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator)'
  234 | unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:234:1: note:   candidate expects 3 arguments, 2 provided
a.cc:77:44: error: expected ';' before ')' token
   77 |         px.erase(unique(px.begin(),it1);it1);
      |                                            ^
      |                                            ;
a.cc:79:13: error: no matching function for call to 'sort(std::vector<int>::iterator, int*&)'
   79 |         sort(py.begin(),it2);
      |         ~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4762:5: note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:5: note:   template argument deduction/substitution failed:
a.cc:79:13: note:   deduced conflicting types for parameter '_RAIter' ('__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'int*')
   79 |         sort(py.begin(),it2);
      |         ~~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   candidate expects 3 arguments, 2 provided
a.cc:80:24: