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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
struct DS{
set<pair<int,int>> st;
int two,ans;
struct node
{
	int x,l,r,o;
	bool operator<(const node&t)const
	{
		return (x!=t.x)?(x<t.x):(l<t.l);
	}
};
set<node> a;
int calc(set<node>::iterator it)
{
	if(it->o!=1) return 0;
	if(it==a.begin()||next(it)==a.end()) return 0;
	auto X=prev(it),Y=next(it);
	if(X->x==it->x&&X->r==it->l-1&&X->o==2&&
	Y->x==it->x&&Y->l==it->r+1&&Y->o==2) return it->r-it->l+1;
	return 0;
}
void del1(int x,int y)
{
	auto it=prev(a.lower_bound((node){x,y+1,y+1,1}));
	ans-=calc(it);
	auto I=*it;
	assert(it->l<=y&&y<=it->r);
	a.erase(it);
	if(I.l<y) a.insert((node){x,I.l,y-1,1});
	if(y<I.r) a.insert((node){x,y+1,I.r,1});
}
void del2(int x,int y)
{
	auto it=a.find((node){x,y,y,2});
	if(it!=a.begin())
	{
		auto z=prev(it);
		ans-=calc(z);
	}
	if(next(it)!=a.end())
	{
		auto z=next(it);
		ans-=calc(z);
	}
	a.erase(it);
}
void ins1(int x,int y)
{
	int l=y,r=y;
	auto it=a.lower_bound((node){x,y,y,1});
	if(it!=a.end())
		if(it->o==1&&it->x==x&&it->l==y+1)
			r=it->r,a.erase(it);
	it=a.lower_bound((node){x,y,y,1});
	// auto it=a.insert((node){x,y,y,2}).first;
	if(it!=a.begin())
	{
		it=prev(it);
		if(it->o==1&&it->x==x&&it->r==y-1)
			l=it->l,a.erase(it);
	}
	ans+=calc(a.insert((node){x,l,r,1}).first);
	// if(next(it)!=a.end())
	// {
		// auto z=next(it);
		// if(z->x==x&&z->l-1==y&&z->o==1)
			// ans-=z->r-z->l+1;
	// }
}
void ins2(int x,int y)
{
	auto it=a.insert((node){x,y,y,2}).first;
	if(it!=a.begin())
	{
		auto z=prev(it);
		if(z->x==x&&z->r+1==y&&z->o==1)
			ans+=calc(z);
	}
	if(next(it)!=a.end())
	{
		auto z=next(it);
		if(z->x==x&&z->l-1==y&&z->o==1)
			ans+=calc(z);
	}
}
void del(int x,int y){
if(!st.count({x,y})) return ;
	bool o[3][3];
	for(int i=-1; i<=1; ++i)
		for(int j=-1; j<=1; ++j)
			o[i+1][j+1]=st.count({x+i,y+j});
	if(
	(o[0][0]&o[0][1]&o[1][0]&o[1][1])|
	(o[0][1]&o[0][2]&o[1][1]&o[1][2])|
	(o[1][0]&o[1][1]&o[2][0]&o[2][1])|
	(o[1][1]&o[1][2]&o[2][1]&o[2][2])
	) --two,del2(x+y,y-x),del2(x+y+1,y-x);
	else if(o[1][2]&o[2][1]&(!o[1][0])&(!o[0][1])) del1(x+y+1,y-x);
	else if(o[1][0]&o[0][1]&(!o[1][2])&(!o[2][1])) del1(x+y,y-x);
}
void ins(int x,int y)
{
	if(!st.count({x,y})) return ;
	bool o[3][3];
	for(int i=-1; i<=1; ++i)
		for(int j=-1; j<=1; ++j)
			o[i+1][j+1]=st.count({x+i,y+j});
	if(
	(o[0][0]&o[0][1]&o[1][0]&o[1][1])|
	(o[0][1]&o[0][2]&o[1][1]&o[1][2])|
	(o[1][0]&o[1][1]&o[2][0]&o[2][1])|
	(o[1][1]&o[1][2]&o[2][1]&o[2][2])
	) ++two,ins2(x+y,y-x),ins2(x+y+1,y-x);
	else if(o[1][2]&o[2][1]&(!o[1][0])&(!o[0][1])) ins1(x+y+1,y-x);
	else if(o[1][0]&o[0][1]&(!o[1][2])&(!o[2][1])) ins1(x+y,y-x);
}
void add(int x,int y)
{
	for(int i=-1; i<=1; ++i)
		for(int j=-1; j<=1; ++j)
			del(x+i,y+j);
	if(st.count({x,y})) st.erase({x,y});
	else st.insert({x,y});
	for(int i=-1; i<=1; ++i)
		for(int j=-1; j<=1; ++j)
			ins(x+i,y+j);
}
}P,Q;
signed main()
{
	read(),read();
	int A=read(),B=read();
	if(A==0) puts("0");
	for(int T=1; T<=A+B; ++T)
	{
		int x=read(),y=read();
		P.add(x,y),Q.add(x,-y);
		// assert(P.two==Q.two);
		if(T>=A) printf("%d\n",(int)P.st.size()-P.two-P.ans-Q.ans);
		// if(T==4691)
		// {
			// for(auto [i,j]:P.st)
				// printf("%lld %lld\n",i,j);
		// }
	}
	return 0;
}