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
118
119
120
121
122
123
124
125
126
127
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define sn second

typedef long long ll;
typedef vector<int> VI;
typedef vector<char> VC;
typedef pair<int, int> PI;

int klocki(int n, int m, int k, int q, vector<vector<bool>> &grid,
           vector<pair<int, int>> &points) {
  queue<pair<int, int>> Q;
  int x, y;
  int res = 0;
  for (int i = 0; i < k; i++) {
    x = points[i].first;
    y = points[i].second;
    // cout << "x = " << x << ", y = " << y << endl;

    bool up_ok = (x == 0 || grid[x - 1][y] == false);
    bool down_ok = (x == n - 1 || grid[x + 1][y] == false);

    bool left_ok = (y == 0 || grid[x][y - 1] == false);
    bool right_ok = (y == m - 1 || grid[x][y + 1] == false);

    if ((down_ok && up_ok) || (right_ok && left_ok)) {
      Q.push({x, y});
    }
    // cout << "---" << endl;
  }

  while (!Q.empty()) {
    x = Q.front().first;
    y = Q.front().second;
    Q.pop();
    if (!grid[x][y]) {
      continue;
    }

    bool up_ok = (x == 0 || grid[x - 1][y] == false);
    bool down_ok = (x == n - 1 || grid[x + 1][y] == false);

    bool left_ok = (y == 0 || grid[x][y - 1] == false);
    bool right_ok = (y == m - 1 || grid[x][y + 1] == false);

    bool up_ocupied = (x > 0 && grid[x - 1][y]);
    bool down_ocupied = (x < n - 1 && grid[x + 1][y]);
    bool left_ocupied = (y > 0 && grid[x][y - 1]);
    bool right_ocupied = (y < m - 1 && grid[x][y + 1]);

    if ((down_ok && up_ok) || (right_ok && left_ok)) {
      res++;
      grid[x][y] = false;
      if (up_ocupied) {
        Q.push({x - 1, y});
      }
      if (down_ocupied) {
        Q.push({x + 1, y});
      }
      if (left_ocupied) {
        Q.push({x, y - 1});
      }
      if (right_ocupied) {
        Q.push({x, y + 1});
      }
    }
  }
  return res;
}

int main() {
  int n, m, k, q;
  cin >> n >> m >> k >> q;

  queue<pair<int, int>> Q;

  vector<vector<bool>> grid(n);
  for (int i = 0; i < n; i++) {
    grid[i].resize(m);
  }

  int x, y;
  vector<pair<int, int>> points(k);
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    x--;
    y--;
    points[i] = {x, y};

    grid[x][y] = true;
  }

  vector<pair<int, int>> queries(q);
  for (int i = 0; i < q; i++) {
    cin >> queries[i].first >> queries[i].second;
    queries[i].first--;
    queries[i].second--;
  }

  cout << klocki(n, m, k, q, grid, points) << endl;

  for (int i = 0; i < q; i++) {
    // for (int j = 0; j < n; j++) {
    //   fill(grid[j].begin(), grid[j].end(), 0);
    // }

    for (int j = 0; j <= i; j++) {
      grid[queries[j].first][queries[j].second] = false;
    }

    for (int j = 0; j < k; j++) {
      grid[points[j].first][points[j].second] = true;
    }

    for (int j = 0; j <= i; j++) {
      grid[queries[j].first][queries[j].second] =
          !grid[queries[j].first][queries[j].second];
    }
    // cout << "KLOCKI" << endl;
    cout << klocki(n, m, k, q, grid, points) << endl;
  }

  return 0;
}