题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4022
题目意思:
告诉n(n<=100000)个点的位置xi,yi(xi,yi<=10^9),有m种操作,每种操作有两个数a,b当a=0时,输出x=b直线上点的个数,然后把这些点去掉。a=1时,输出y=b直线上点的个数,并去掉这些点。
解题思路:
先把n个点的横纵坐标映射成1,2....,然后来一条直线,就二分找到位置,输出对应的点个数,再把另一端的相应点给去掉。
代码:
//#include<CSpreadSheet.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define Maxn 110000
struct Inf
{
int x,y;
}inf[Maxn];
int n,m,cnth,cntv;
multiset<int>myv1[Maxn];
multiset<int>myv2[Maxn];
map<int,int>myp1;
map<int,int>myp2;
bool cmp1(struct Inf a,struct Inf b)
{
if(a.x!=b.x)
return a.x<b.x;
return a.y<b.y;
}
bool cmp2(struct Inf a,struct Inf b)
{
if(a.y!=b.y)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%d%d",&n,&m))
{
if(!(n+m))
break;
myp1.clear();
myp2.clear();
for(int i=1;i<=n;i++)
{
scanf("%d%d",&inf[i].x,&inf[i].y);
myv1[i].clear();
myv2[i].clear();
}
sort(inf+1,inf+n+1,cmp1);
cnth=0;
inf[0].x=inf[0].y=-INF;
for(int i=1;i<=n;i++)
{
if(inf[i].x!=inf[i-1].x)
{
cnth++;
myp1[inf[i].x]=cnth; //横坐标对应的下标
}
myv1[cnth].insert(inf[i].y); //表示当前序号的横坐标 对应的点的个数
}
sort(inf+1,inf+n+1,cmp2);
cntv=0;
for(int i=1;i<=n;i++)
{
if(inf[i].y!=inf[i-1].y)
{
cntv++;
myp2[inf[i].y]=cntv;
}
myv2[cntv].insert(inf[i].x);
}
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(!x) //ÊúÖ±·½Ïò
{
//int tt=lower_bound(px+1,px+cnth+1,y)-px;
int tt=myp1[y];
if(!tt) //没有
{
printf("0\n");
continue;
}
printf("%d\n",myv1[tt].size()); //输出
set<int>::iterator it;
for(it=myv1[tt].begin();it!=myv1[tt].end();it++) //去掉相应的点
{
int cur=*it;
//int temp=lower_bound(py+1,py+cntv+1,cur)-py;
int temp=myp2[cur];
if(temp)
{
if(!myv2[temp].empty())
myv2[temp].erase(y);
}
}
myv1[tt].clear();
}
else
{
int tt=myp2[y];//=lower_bound(py+1,py+cntv+1,y)-py;
if(!tt)
{
printf("0\n");
continue;
}
printf("%d\n",myv2[tt].size());
set<int>::iterator it;
for(it=myv2[tt].begin();it!=myv2[tt].end();it++)
{
int cur=*it;
int temp=myp1[cur];//=lower_bound(px+1,px+cnth+1,cur)-px;
if(temp)
{
if(!myv1[temp].empty())
myv1[temp].erase(y);
}
}
myv2[tt].clear();
}
}
putchar('\n');
}
return 0;
}