一开始并查集写的,ga掉。set应用一道非常好的题目。
```
#include <bits/stdc++.h>
#include <set>
#define sii set<int>::iterator
using namespace std;
int h,w,q,ans;
set<int> s1[400007],s2[400007];
void del(int x,int y){
//printf(" %d %d\n",x,y);
s1[x].erase(y);
s2[y].erase(x);
ans++;
}
signed main(){
// cout<<"yyy"<<endl;
scanf("%d%d%d",&h,&w,&q);
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
// cout<<"xxx"<<endl;
s1[i].insert(j);
s2[j].insert(i);
}
}
for(int i=1,x,y;i<=q;i++){
scanf("%d%d",&x,&y);
if(*s1[x].lower_bound(y)==y) del(x,y);
else{
sii p=s1[x].lower_bound(y);
if(p!=s1[x].begin()){
p--;
del(x,*p);
//p++;
}
p=s1[x].lower_bound(y);
if(p!=s1[x].end()){
del(x,*p);
}
sii q=s2[y].lower_bound(x);
if(q!=s2[y].begin()){
q--;
del(*q,y);
//q++;
}
q=s2[y].lower_bound(x);
if(q!=s2[y].end()){
del(*q,y);
}
}
}
printf("%d\n",h*w-ans);
return 0;
}
```
标签:set,Explosion,int,abc370D,Cross,erase,ans From: https://www.cnblogs.com/caterpillor/p/18414352