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
#define _CRT_SECURE_NO_WARNINGS                                                 
#include <iostream>                                                             
#include <algorithm>                                                            
#include <vector>                                                               
#include <cmath>                                                                
#include <map>                                                                  
#include <queue>                                                                
#include <set>                                                                  
#include <numeric>                                                              
#include <stack>                                                                
#include <iomanip>   
#include <unordered_map>
using namespace std;
using ll = long long int;
#define debug(x) cout << #x << " = " << x << endl;
bool czykw(pair<int, int> para,set<pair<int,int>>& s)
{
    int x = para.first;
    int y = para.second;
    if (s.find({ x - 1,y - 1 }) != s.end() && s.find({ x,y - 1 }) != s.end() && s.find({ x - 1,y }) != s.end())//gora lewo
        return true;
    if (s.find({ x + 1,y - 1 }) != s.end() && s.find({ x,y - 1 }) != s.end() && s.find({ x + 1,y }) != s.end())//gora prawo
        return true;
    if (s.find({ x + 1,y }) != s.end() && s.find({ x + 1,y + 1 }) != s.end() && s.find({ x,y + 1}) != s.end())//dol prawo
        return true;
    if (s.find({ x - 1,y + 1}) != s.end() && s.find({ x - 1,y }) != s.end() && s.find({ x,y + 1 }) != s.end())//dol lewo
        return true;
    return false;
}
void update(pair<int, int> para, set<pair<int, int>>& usuwalne, set<pair<int, int>>& s)
{
    int x = para.first;
    int y = para.second;
    for (int i = x - 1; i <= x + 1; i++)
    {
        for (int j = y - 1; j <= y + 1; j++)
        {
            if (s.find({i,j}) != s.end() && czykw({i,j}, s) && usuwalne.find({i,j}) != usuwalne.end())
            {
                usuwalne.erase({i,j});
            }
            else if (s.find({ i,j }) != s.end() &&  (!czykw({i,j}, s)) && usuwalne.find({i,j}) == usuwalne.end())
            {
                usuwalne.insert({i,j});
            }
        }
    }
}
void solve()
{
    int n, m, k, q;
    cin >> n >> m >> k >> q;
    set<pair<int, int>>s;
    set<pair<int, int>>usuwalne;
    for (int i = 0; i < k; i++)
    {
        int x, y;
        cin >> x >> y;
        s.insert({ x, y });
    }
    int ileok = 0;
    for (auto para : s)
    {
        if (!czykw(para, s))
        {
            ileok++;
            usuwalne.insert(para);
        }
    }
    vector<int>odp;
    odp.push_back(usuwalne.size());
    while (q--)
    {
        int x,y;
        cin >> x>> y;
        if (s.find({ x,y }) == s.end())
        {
            s.insert({ x,y });
        }
        else
        {
            s.erase({ x,y });
            usuwalne.erase({ x,y });
        }
        update({ x,y }, usuwalne, s);
        odp.push_back(usuwalne.size());
    }
    for (int i = 0; i < odp.size(); i++)
    {
        cout << odp[i] << "\n";
    }

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int t;                                                                    
    //cin >> t;                                                                 
    //while (t--)                                                               
    //{                                                                         
        solve();
    //}                                                                         
    return 0;
}