Ac代码如下
#include<bits/stdc++.h>
using namespace std;
const long long N = 4e5+5;
long long n, m, q;
set<long long> xk[N], yk[N], se;//xk横着 yk竖着
map<long long, long long> bi[N];
long long x1, x2, y11, y2;
void lowe(long long x, long long y){
set<long long>::iterator it;
it = xk[x].lower_bound(y);
x1 = *it;
it--; x2 = *it;
it = yk[y].lower_bound(x);
y11 = *it;
it--; y2 = *it;
}
void dete(long long x, long long y){
if(y != m+1 && y != 0)xk[x].erase(y);
if(x != n+1 && x != 0)yk[y].erase(x);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for(long long i=1;i<=n;i++){
xk[i].insert(0); xk[i].insert(m+1);
}
for(long long j=1;j<=m;j++){
yk[j].insert(0); yk[j].insert(n+1);
}
for(long long i=1;i<=n;i++){
for(long long j=1;j<=m;j++){
xk[i].insert(j);
yk[j].insert(i);
}
}
long long xc, yc;
while(q--){
cin >> xc >> yc;
if(bi[xc][yc] == 0){
bi[xc][yc] = 1;
dete(xc, yc);
}
else{
lowe(xc, yc);
bi[xc][x1] = bi[xc][x2] = bi[y11][yc] = bi[y2][yc] = 1;
dete(xc, x1);
dete(xc, x2);
dete(y11, yc);
dete(y2, yc);
}
}
long long ans = 0;
for(long long i=1;i<=n;i++){
for(long long j=1;j<=m;j++){
ans += (bi[i][j]==0);
}
}
cout << ans;
return 0;
}