1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5;

#define st first
#define nd second

typedef pair<int,int> pun;
typedef long long ll;

#define mp make_pair
int n,m;


map<pun, bool> board;
map<pun, bool> locked;
map<pun, bool> know_how_to_remove;
int locked_cnt = 0;
int all_cnt = 0;


bool empty(int x, int y) {
	return (not board[mp(x, y)]) || know_how_to_remove[mp(x, y)];
}

bool compute_if_locked(int x, int y) {
	if (not board[mp(x, y)]) return false;
	if (empty(x-1, y) && empty(x+1, y)) return false;
	if (empty(x, y-1) && empty(x, y+1)) return false;
	return true;
}

bool inbounds(int x, int y) {
	return x >= 1 && x <= n && y >= 1 && y <= m;
}

void update_locked_state(int x, int y) {
	if (not inbounds(x,y)) return;
	bool s =  compute_if_locked(x, y);
	if (locked[mp(x, y)] == s && (s != false || know_how_to_remove[mp(x,y)] == true)) {
		return;
	}
	locked_cnt -= locked[mp(x, y)];
	locked[mp(x,y)] = s;
	locked_cnt += locked[mp(x,y)];

	if (s == false) know_how_to_remove[mp(x,y)] = true;


	for (int i = -1; i <= 1; i ++) {
		for (int j = -1; j <= 1; j ++) {
			if (i != 0 || j != 0) update_locked_state(x + i, y + j);
		}
	}


	return;
}

void set_board(int a, int b, bool state) {
	if (board[mp(a,b)] == state) return;
	if (state) all_cnt ++;
	else all_cnt --;
	board[mp(a,b)] = state;


	if (state == true) {
		know_how_to_remove.clear();
		for (auto p : board) {
			if (p.second) update_locked_state(p.st.st, p.st.nd);
		}
	}
	else {
		for (int i = -1; i <= 1; i ++) {
			for (int j = -1; j <= 1; j ++) {
				update_locked_state(a+i, b+j);
			}
		}
	}
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int c, q;
	cin >> n >> m >> c >> q;
	for (int i = 0; i < c; i ++) {
		int x, y;
		cin >> x >> y;
		board[mp(x,y)] = true;
	}
	all_cnt = board.size();
	for (auto p : board) {
		update_locked_state(p.st.st, p.st.nd);
	}
	cout << all_cnt - locked_cnt << "\n";
	for (int j = 0; j < q; j ++) {
		int x, y;
		cin >> x >> y;
		set_board(x, y, not board[mp(x,y)]);
		
		cout << all_cnt - locked_cnt << "\n";

/*		if (j == 270) {
			for (int i = 1; i <= n; i ++) {
				for(int j = 1; j <= m; j ++) {
					cerr << board[mp(i,j)];
				}
				cerr <<"\n";
			}
			cerr << all_cnt - locked_cnt << "\n";

		}	
*/	}
}