#include <bits/stdc++.h>
using namespace std;
int n,m,k,q,b,i,x,y,z,sx,sy,ex,ey,j;
set <array<int,2>> xy;
set <array<int,3>> xys;
array<int,3> aa,bb,cc;
array<int,2> dd;
set <array<int,2>> LU, LD,RU,RD;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k >> q;
z=0;
for(i=0;i<k;i++) {
cin >> x >> y;
xy.insert({x,y});
}
for (j=0;j<=q;j++) {
z=0;
if(j>0) {
xys={};
LU={};
RU={};
LD={};
RD={};
cin >> x >> y;
if(xy.find({x,y})!=xy.end()) xy.erase({x,y});
else xy.insert({x,y});
}
for(auto it : xy) {
//if(j==2214)
// cout << it[0] << ' ' << it[1] << "H\n";
b=0;
if(xy.find({it[0]+1,it[1]})!=xy.end())
b|=1;
if(xy.find({it[0]-1,it[1]})!=xy.end())
b|=2;
if(xy.find({it[0],it[1]+1})!=xy.end())
b|=4;
if(xy.find({it[0],it[1]-1})!=xy.end())
b|=8;
if(b==5 || b==10) b|=16;
else if(b==6 || b==9) b|=32;
else if(b==7 and (xy.find({it[0]+1,it[1]+1})!=xy.end() or xy.find({it[0]-1,it[1]+1})!=xy.end()))
b|=64;
else if(b==11 and (xy.find({it[0]+1,it[1]-1})!=xy.end() or xy.find({it[0]-1,it[1]-1})!=xy.end()))
b|=64;
else if(b==13 and (xy.find({it[0]+1,it[1]+1})!=xy.end() or xy.find({it[0]+1,it[1]-1})!=xy.end()))
b|=64;
else if(b==14 and (xy.find({it[0]-1,it[1]+1})!=xy.end() or xy.find({it[0]-1,it[1]-1})!=xy.end()))
b|=64;
else if(b==15 and (xy.find({it[0]-1,it[1]+1})!=xy.end() or xy.find({it[0]-1,it[1]-1})!=xy.end() or xy.find({it[0]+1,it[1]+1})!=xy.end() or xy.find({it[0]+1,it[1]-1})!=xy.end()))
b|=64;
xys.insert({it[0],it[1],b});
}
for(auto it : xys) {
if((it[2]&15)==5) {
aa=*xys.lower_bound({it[0]+1,it[1],0});
if((aa[2]&15)!=10)
RU.insert({it[0]+1+it[1],-2*it[1]});
aa=*xys.lower_bound({it[0],it[1]+1,0});
if((aa[2]&15)!=10)
LD.insert({it[0]+it[1]+1,2*(it[1]+1)});
}
if((it[2]&15)==10) {
aa=*xys.lower_bound({it[0],it[1]-1,0});
if((aa[2]&15)!=5)
RU.insert({it[0]+it[1],-(2*it[1]-1)});
aa=*xys.lower_bound({it[0]-1,it[1],0});
if((aa[2]&15)!=5)
LD.insert({it[0]+it[1],(2*it[1]+1)});
}
if((it[2]&15)==6) {
aa=*xys.lower_bound({it[0]-1,it[1],0});
if((aa[2]&15)!=9)
LU.insert({it[0]-1-it[1],-2*it[1]});
aa=*xys.lower_bound({it[0],it[1]+1,0});
if((aa[2]&15)!=9)
RD.insert({it[0]-1-it[1],2*(it[1]+1)});
}
if((it[2]&15)==9) {
aa=*xys.lower_bound({it[0],it[1]-1,0});
if((aa[2]&15)!=6)
LU.insert({it[0]-it[1],-(2*it[1]-1)});
aa=*xys.lower_bound({it[0]+1,it[1],0});
if((aa[2]&15)!=6)
RD.insert({it[0]-it[1],(2*it[1]+1)});
}
}
for(auto it : xys) {
if(it[2]<16) {z++;
//cout << it[0] << ' ' << it[1] << "P\n";
}
if((it[2]&15)==5) {
//cout << it[0] << ' ' << it[1] << "LU\n";
}
}
for(auto tt: LU) {
//cout << tt[0] << ' ' << tt[1] << "G\n";
dd=*RD.upper_bound({tt[0],-tt[1]});
//cout << dd[0] << ' ' << dd[1] << "H\n";
if(tt[1]%2) {
sy=(1-tt[1])/2-1;
sx=tt[0]+sy+1;
}
else {
sy=-tt[1]/2;
sx=tt[0]+sy;
}
if(dd[1]%2) {
ey=(1+dd[1])/2-1;
ex=dd[0]+ey+1;
}
else {
ey=dd[1]/2;
ex=dd[0]+ey;
}
bb=*xys.lower_bound({sx,sy,0});
cc=*xys.lower_bound({ex,ey,0});
if(bb[2]<16 or cc[2]<16) {
z+=dd[1]+tt[1]-1;
//cout << bb[0] << ' ' << bb[1] << ' ' << (bb[2]&15) << "HP\n";
//cout << sx << ' ' << sy << "HP\n";
//cout << cc[0] << ' ' << cc[1] << ' ' << (cc[2]&15) << "HP\n";
//cout << ex << ' ' << ey << "HP\n";
}
}
for(auto tt: RU) {
//cout << tt[0] << ' ' << tt[1] << "Gx\n";
dd=*LD.upper_bound({tt[0],-tt[1]});
//cout << dd[0] << ' ' << dd[1] << "Hx\n";
if(tt[1]%2) {
sy=(1-tt[1])/2-1;
sx=tt[0]-sy-1;
}
else {
sy=-tt[1]/2;
sx=tt[0]-sy;
}
if(dd[1]%2) {
ey=(1+dd[1])/2-1;
ex=dd[0]-ey-1;
}
else {
ey=dd[1]/2;
ex=dd[0]-ey;
}
bb=*xys.lower_bound({sx,sy,0});
cc=*xys.lower_bound({ex,ey,0});
//cout << bb[0] << ' ' << bb[1] << ' ' << (bb[2]&15) << "HP\n";
//cout << sx << ' ' << sy << "HP\n";
//cout << cc[0] << ' ' << cc[1] << ' ' << (cc[2]&15) << "HP\n";
//cout << ex << ' ' << ey << "HP\n";
if(bb[2]<16 or cc[2]<16){
z+=dd[1]+tt[1]-1;
//cout << bb[0] << ' ' << bb[1] << "HP\n";
//cout << sx << ' ' << sy << "HP\n";
}
}
cout << z << '\n';
}
}
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 158 159 160 161 162 163 164 165 166 | #include <bits/stdc++.h> using namespace std; int n,m,k,q,b,i,x,y,z,sx,sy,ex,ey,j; set <array<int,2>> xy; set <array<int,3>> xys; array<int,3> aa,bb,cc; array<int,2> dd; set <array<int,2>> LU, LD,RU,RD; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k >> q; z=0; for(i=0;i<k;i++) { cin >> x >> y; xy.insert({x,y}); } for (j=0;j<=q;j++) { z=0; if(j>0) { xys={}; LU={}; RU={}; LD={}; RD={}; cin >> x >> y; if(xy.find({x,y})!=xy.end()) xy.erase({x,y}); else xy.insert({x,y}); } for(auto it : xy) { //if(j==2214) // cout << it[0] << ' ' << it[1] << "H\n"; b=0; if(xy.find({it[0]+1,it[1]})!=xy.end()) b|=1; if(xy.find({it[0]-1,it[1]})!=xy.end()) b|=2; if(xy.find({it[0],it[1]+1})!=xy.end()) b|=4; if(xy.find({it[0],it[1]-1})!=xy.end()) b|=8; if(b==5 || b==10) b|=16; else if(b==6 || b==9) b|=32; else if(b==7 and (xy.find({it[0]+1,it[1]+1})!=xy.end() or xy.find({it[0]-1,it[1]+1})!=xy.end())) b|=64; else if(b==11 and (xy.find({it[0]+1,it[1]-1})!=xy.end() or xy.find({it[0]-1,it[1]-1})!=xy.end())) b|=64; else if(b==13 and (xy.find({it[0]+1,it[1]+1})!=xy.end() or xy.find({it[0]+1,it[1]-1})!=xy.end())) b|=64; else if(b==14 and (xy.find({it[0]-1,it[1]+1})!=xy.end() or xy.find({it[0]-1,it[1]-1})!=xy.end())) b|=64; else if(b==15 and (xy.find({it[0]-1,it[1]+1})!=xy.end() or xy.find({it[0]-1,it[1]-1})!=xy.end() or xy.find({it[0]+1,it[1]+1})!=xy.end() or xy.find({it[0]+1,it[1]-1})!=xy.end())) b|=64; xys.insert({it[0],it[1],b}); } for(auto it : xys) { if((it[2]&15)==5) { aa=*xys.lower_bound({it[0]+1,it[1],0}); if((aa[2]&15)!=10) RU.insert({it[0]+1+it[1],-2*it[1]}); aa=*xys.lower_bound({it[0],it[1]+1,0}); if((aa[2]&15)!=10) LD.insert({it[0]+it[1]+1,2*(it[1]+1)}); } if((it[2]&15)==10) { aa=*xys.lower_bound({it[0],it[1]-1,0}); if((aa[2]&15)!=5) RU.insert({it[0]+it[1],-(2*it[1]-1)}); aa=*xys.lower_bound({it[0]-1,it[1],0}); if((aa[2]&15)!=5) LD.insert({it[0]+it[1],(2*it[1]+1)}); } if((it[2]&15)==6) { aa=*xys.lower_bound({it[0]-1,it[1],0}); if((aa[2]&15)!=9) LU.insert({it[0]-1-it[1],-2*it[1]}); aa=*xys.lower_bound({it[0],it[1]+1,0}); if((aa[2]&15)!=9) RD.insert({it[0]-1-it[1],2*(it[1]+1)}); } if((it[2]&15)==9) { aa=*xys.lower_bound({it[0],it[1]-1,0}); if((aa[2]&15)!=6) LU.insert({it[0]-it[1],-(2*it[1]-1)}); aa=*xys.lower_bound({it[0]+1,it[1],0}); if((aa[2]&15)!=6) RD.insert({it[0]-it[1],(2*it[1]+1)}); } } for(auto it : xys) { if(it[2]<16) {z++; //cout << it[0] << ' ' << it[1] << "P\n"; } if((it[2]&15)==5) { //cout << it[0] << ' ' << it[1] << "LU\n"; } } for(auto tt: LU) { //cout << tt[0] << ' ' << tt[1] << "G\n"; dd=*RD.upper_bound({tt[0],-tt[1]}); //cout << dd[0] << ' ' << dd[1] << "H\n"; if(tt[1]%2) { sy=(1-tt[1])/2-1; sx=tt[0]+sy+1; } else { sy=-tt[1]/2; sx=tt[0]+sy; } if(dd[1]%2) { ey=(1+dd[1])/2-1; ex=dd[0]+ey+1; } else { ey=dd[1]/2; ex=dd[0]+ey; } bb=*xys.lower_bound({sx,sy,0}); cc=*xys.lower_bound({ex,ey,0}); if(bb[2]<16 or cc[2]<16) { z+=dd[1]+tt[1]-1; //cout << bb[0] << ' ' << bb[1] << ' ' << (bb[2]&15) << "HP\n"; //cout << sx << ' ' << sy << "HP\n"; //cout << cc[0] << ' ' << cc[1] << ' ' << (cc[2]&15) << "HP\n"; //cout << ex << ' ' << ey << "HP\n"; } } for(auto tt: RU) { //cout << tt[0] << ' ' << tt[1] << "Gx\n"; dd=*LD.upper_bound({tt[0],-tt[1]}); //cout << dd[0] << ' ' << dd[1] << "Hx\n"; if(tt[1]%2) { sy=(1-tt[1])/2-1; sx=tt[0]-sy-1; } else { sy=-tt[1]/2; sx=tt[0]-sy; } if(dd[1]%2) { ey=(1+dd[1])/2-1; ex=dd[0]-ey-1; } else { ey=dd[1]/2; ex=dd[0]-ey; } bb=*xys.lower_bound({sx,sy,0}); cc=*xys.lower_bound({ex,ey,0}); //cout << bb[0] << ' ' << bb[1] << ' ' << (bb[2]&15) << "HP\n"; //cout << sx << ' ' << sy << "HP\n"; //cout << cc[0] << ' ' << cc[1] << ' ' << (cc[2]&15) << "HP\n"; //cout << ex << ' ' << ey << "HP\n"; if(bb[2]<16 or cc[2]<16){ z+=dd[1]+tt[1]-1; //cout << bb[0] << ' ' << bb[1] << "HP\n"; //cout << sx << ' ' << sy << "HP\n"; } } cout << z << '\n'; } } |
English