Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <iterator>
#include <bitset>
#include <random>
#include <assert.h>
#include <unordered_map>
#include <array>
#include <ctime>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second
#define MP make_pair
#define umap unordered_map

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
typedef unsigned int uint;

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

vector<vector<short>> field;

int w, h;
void bfs(int r, int c){

	queue<P> q;
	q.push(MP(r, c));
	field[r][c] = 1;
	while (!q.empty()){
		int y = q.front().first;
		int x = q.front().second;
		q.pop();

		for (int i = 0; i < 4; ++i){
			int nx = x + dx[i], ny = y + dy[i];
			if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if (field[ny][nx]) continue;
			field[ny][nx] = 1;
			q.push(MP(ny, nx));
		}
	}
}

int main(){
	while (cin >> w >> h, w|h){
		int n;
		cin >> n;
		vector<int> x(n * 2), y(n * 2);
		rep(i, n * 2){
			cin >> x[i] >> y[i];
		}
		vector<int> vx = x, vy = y;
		vx.emplace_back(0), vx.emplace_back(w);
		vy.emplace_back(0), vy.emplace_back(h);
		sort(ALL(vx));
		vx.erase(unique(ALL(vx)), vx.end());
		sort(ALL(vy));
		vy.erase(unique(ALL(vy)), vy.end());

		for (auto &e : x) e = lower_bound(ALL(vx), e) - vx.begin();
		for (auto &e : y) e = lower_bound(ALL(vy), e) - vy.begin();

		w = vx.back() - 1, h = vy.back() - 1;

		field = vector<vector<int>>(h + 1, vector<int>(w + 1, 0));

		rep(i, n){
			++field[y[i * 2]][x[i * 2]];
			--field[y[i * 2 + 1]][x[i * 2]];
			--field[y[i * 2]][x[i * 2 + 1]];
			++field[y[i * 2 + 1]][x[i * 2 + 1]];
		}

		rep(i, h) rep(j, w){
			field[i + 1][j] += field[i][j];
			field[i][j + 1] += field[i][j];
			field[i + 1][j + 1] -= field[i][j];
		}

		int ans = 0;
		rep(i, h) rep(j, w){
			if (field[i][j]) continue;
			bfs(i, j);
			++ans;
			//rep(i, h){
			//	rep(j, w) cout << field[i][j];
			//	cout << '\n';
			//} cout << '\n';
		}
		cout << ans << endl;
	}


	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:94:73: error: no match for 'operator=' (operand types are 'std::vector<std::vector<short int> >' and 'std::vector<std::vector<int> >')
   94 |                 field = vector<vector<int>>(h + 1, vector<int>(w + 1, 0));
      |                                                                         ^
In file included from /usr/include/c++/14/vector:72,
                 from a.cc:2:
/usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<short int>; _Alloc = std::allocator<std::vector<short int> >]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'const std::vector<std::vector<short int> >&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = std::vector<short int>; _Alloc = std::allocator<std::vector<short int> >]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'std::vector<std::vector<short int> >&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = std::vector<short int>; _Alloc = std::allocator<std::vector<short int> >]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'std::initializer_list<std::vector<short int> >'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~