//hdu5091 线段树+扫描线 矩形最大覆盖
/*
http://blog.csdn.net/u010787640/article/details/40948255
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <map>
#include <bitset>
using namespace std;
#define ll long long 
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define scfd(a) scanf("%d",a)
#define scflf(a) scanf("%lf",a)
#define scfs(a) scanf("%s",a)
#define ptfd(a) printf("%d\n",a)
#define ptfs(a) printf("%s\n",a)
#define showd(a,b) printf(a"=%d\n",b)
#define showlf(a,b) printf(a"=%lf\n",b)
#define shows(a,b) printf(a"=%s\n",b)
#define mmcp(a,b) memcpy(a,b,sizeof(b))
const int MAXN=30000+5;
int n,w,h;
struct point{
	int x;
	int y;
	int v;
	bool operator<(point &a)const{
		return x<a.x;
	}
}p[MAXN];
int stn[MAXN*8];
int laz[MAXN*8];
void push_down(int now){
	laz[now<<1]+=laz[now];laz[(now<<1)+1]+=laz[now];
	stn[now<<1]+=laz[now];stn[(now<<1)+1]+=laz[now];
	laz[now]=0;
}
void push_up(int now){
	stn[now]=max(stn[now<<1],stn[(now<<1)+1]);
}
void update(int now,int l,int r,int tl,int tr,int t){
	if(tl<=l&&tr>=r){
		laz[now]+=t;
		stn[now]+=t;
		return;
	}
	push_down(now);
	int mid=(l+r)/2;
	if(tl<mid)
		update(now<<1,l,mid,tl,tr,t);
	if(tr>mid)
		update((now<<1)+1,mid,r,tl,tr,t);
	push_up(now);
}
int find(int now,int l,int r,int tl,int tr){
	if(tl<=l&&tr>=r)
		return stn[now];
	push_down(now);
	int mid=(l+r)/2,ans=-1;
	if(tl<mid)
		ans=max(ans,find(now<<1,l,mid,tl,tr));
	if(tr>mid)
		ans=max(ans,find((now<<1)+1,mid,r,tl,tr));
	return ans;
}
void init(){
	ms(stn,0);
	ms(laz,0);
}
int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	while(scfd(&n)){
		init();
		if(n<0)break;
		scanf("%d%d",&w,&h);
		fr(i,1,n){
			scanf("%d%d",&p[i].x,&p[i].y);
			p[i].x+=MAXN,p[i].y+=MAXN;p[i].v=1;
			p[i+n].x=p[i].x+w,p[i+n].y=p[i].y,p[i+n].v=-1;
		}
		sort(p+1,p+2*n+1);
		int ans=-1;
		fr(i,1,2*n){
			update(1,1,60005,p[i].y,p[i].y+h+1,p[i].v);
			ans=max(ans,find(1,1,60005,1,60005));
		}
		ptfd(ans);
	}
	return 0;
}
 posted on 2017-09-22 17:17  cylcy  阅读(90)  评论(0编辑  收藏  举报