Language: C++

#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n;
int w,h;
int x1[1010],x2[1010];
int y1[1010],y2[1010];
bool board[6000][6000];

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int compress(int* z1,int* z2,int len){
	vi zs;
	rep(i,n)for(int d=-1;d<=1;d++){
		int tz1=z1[i]+d,tz2=z2[i]+d;
		if(0<=tz1&&tz1<=len) zs.pb(tz1);
		if(0<=tz2&&tz2<=len) zs.pb(tz2);
	}
	sort(zs.begin(),zs.end());
	zs.erase(unique(zs.begin(),zs.end()),zs.end());
	rep(i,n){
		z1[i]=find(zs.begin(),zs.end(),z1[i])-zs.begin();
		z2[i]=find(zs.begin(),zs.end(),z2[i])-zs.begin();
	}
	return zs.size();
}

int main(void){
	while(cin >> w >> h){
		if(w==0||h==0)
			break;
		cin >> n;
		rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		rep(i,n) x2[i]--,y2[i]--;
		w=compress(x1,x2,w-1);
		h=compress(y1,y2,h-1);
		clr(board,0);
		rep(i,n){
			for(int y=y1[i];y<=y2[i];y++)
				for(int x=x1[i];x<=x2[i];x++)
					board[y][x]=true;
		}

		int ans=0;
		rep(y,h)rep(x,w){
			if(board[y][x])
				continue;
			ans++;

			queue<pii> q;
			q.push(mp(x,y));
			while(!q.empty()){
				int sx=q.front().first;
				int sy=q.front().second;
				q.pop();
				rep(i,4){
					int nx=sx+dx[i];
					int ny=sy+dy[i];
					if(nx<0||w<=nx||ny<0||h<=ny) continue;
					if(board[ny][nx]) continue;
					board[ny][nx]=true;
					q.push(mp(nx,ny));
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Compiler output:
a.cc:35:12: error: 'int y1 [1010]' redeclared as different kind of entity
   35 | int y1[1010],y2[1010];
      |            ^
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:257:1: note: previous declaration 'double y1(double)'
  257 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:62:46: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                              ^
a.cc:62:39: error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} and 'double(double) noexcept')
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                          ~~~~~~~~~~~~ ^~ ~~~~~
      |                              |               |
      |                              |               double(double) noexcept
      |                              std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
In file included from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  170 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:170:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double (*)(double) noexcept'
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  174 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:174:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: invalid conversion from 'double (*)(double) noexcept' to 'short int' [-fpermissive]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
      |                                              |
      |                                              double (*)(double) noexcept
a.cc:62:46: error: cannot bind rvalue '(short int)(y1 + ((sizetype)i))' to 'short int&'
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  177 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:177:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: invalid conversion from 'double (*)(double) noexcept' to 'short unsigned int' [-fpermissive]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
      |                                              |
      |                                              double (*)(double) noexcept
a.cc:62:46: error: cannot bind rvalue '(short unsigned int)(y1 + ((sizetype)i))' to 'short unsigned int&'
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  181 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:181:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
      |                                              |
      |                                              double (*)(double) noexcept
a.cc:62:46: error: cannot bind rvalue '(int)(y1 + ((sizetype)i))' to 'int&'
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:184:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: invalid conversion from 'double (*)(double) noexcept' to 'unsigned int' [-fpermissive]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
      |                                              |
      |                                              double (*)(double) noexcept
a.cc:62:46: error: cannot bind rvalue '(unsigned int)(y1 + ((sizetype)i))' to 'unsigned int&'
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:188:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: invalid conversion from 'double (*)(double) noexcept' to 'long int' [-fpermissive]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
      |                                              |
      |                                              double (*)(double) noexcept
a.cc:62:46: error: cannot bind rvalue '(long int)(y1 + ((sizetype)i))' to 'long int&'
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:192:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: invalid conversion from 'double (*)(double) noexcept' to 'long unsigned int' [-fpermissive]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
      |                                              |
      |                                              double (*)(double) noexcept
a.cc:62:46: error: cannot bind rvalue '(long unsigned int)(y1 + ((sizetype)i))' to 'long unsigned int&'
/usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  199 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:199:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: invalid conversion from 'double (*)(double) noexcept' to 'long long int' [-fpermissive]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
      |                                              |
      |                                              double (*)(double) noexcept
a.cc:62:46: error: cannot bind rvalue '(long long int)(y1 + ((sizetype)i))' to 'long long int&'
/usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  203 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:203:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: invalid conversion from 'double (*)(double) noexcept' to 'long long unsigned int' [-fpermissive]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
      |                                              |
      |                                              double (*)(double) noexcept
a.cc:62:46: error: cannot bind rvalue '(long long unsigned int)(y1 + ((sizetype)i))' to 'long long unsigned int&'
/usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  328 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/14/istream:328:7: note:   conversion of argument 1 would be ill-formed:
a.cc:62:46: error: invalid conversion from 'double (*)(double) noexcept' to 'void*' [-fpermissive]
   62 |                 rep(i,n) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      |                                          ~~~~^
      |                                              |
      |                                              double (*)(double) no