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
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <tuple>
#include <bitset>

using namespace std;

#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define x first
#define y second

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<ll> vll;


struct hash_set {
    size_t operator()(const std::pair<ll, ll>& p) const {
        return static_cast<size_t>(p.first) * 200003 + p.second;  
    }
};
unordered_set<pll, hash_set> tiles;
unordered_set<pll, hash_set> current_tiles;
ll ans = 0;

inline bool can_delete_tile(ll x, ll y){
    if(current_tiles.find(mp(x+1, y))==current_tiles.end() && current_tiles.find(mp(x-1, y))==current_tiles.end()){
        return true;
    }

    if(current_tiles.find(mp(x, y+1))==current_tiles.end() && current_tiles.find(mp(x, y-1))==current_tiles.end()){
        return true;
    }

    return false;
}

inline void process_q(){
    bool has_changed = true;
    while(has_changed){
        has_changed = false;

        vector<pii> remove;

        for(auto tile: current_tiles){
            if(can_delete_tile(tile.x, tile.y)){
                has_changed = true;
                ans++;
                remove.pb(mp(tile.x, tile.y));
            }
        }
        for(auto tile: remove){
            current_tiles.erase(tile);
        }

    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n, m, k, q;
    cin >> n >> m >> k >> q;

    for(ll i=0; i<k; i++){
        ll x, y;
        cin >> x >> y;
        tiles.insert(mp(x, y));
    }

    current_tiles = tiles;
    process_q();
    cout << ans << "\n";
    ans = 0;

    for(ll i=0; i<q; i++){
        ll x, y;
        cin >> x >> y;

        if(tiles.find(mp(x, y))!=tiles.end()){
            tiles.erase(mp(x, y));
        }else{
            tiles.insert(mp(x, y));
        }
        current_tiles = tiles;
    
        process_q();
        cout << ans << "\n";
        ans = 0;
    }

    return 0;
}