标签:des style http io os ar for sp div
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
#include <cstring>
using namespace std;
struct node{
int t,pos,st;
}ha[200000];
int x1,x2,v;
int _max;
int n,w,h;
int cmp(node x,node y)
{
return (x.t<y.t);//依照时间先后顺序排序,先删除点再加入点
}
int maxv[400000],addv[400000];
void maintain(int o,int L,int R)
{
int lc=o<<1;
int rc=lc+1;
maxv[o]=0;
if (R>L)
{
maxv[o]=max(maxv[lc],maxv[rc]);
}
maxv[o]+=addv[o];
}
void update(int o,int L,int R)
{
int lc=o<<1;
int rc=lc+1;
if (x1<=L&&x2>=R) addv[o]+=v;
else {
int M=L+(R-L)/2;
if (x1<=M) update(lc,L,M);
if (x2>M) update(rc,M+1,R);
}
maintain(o,L,R);
}
void query(int o,int L,int R,int add)
{
int lc=o<<1;
int rc=lc+1;
if (x1<=L&&x2>=R) _max=max(_max,maxv[o]+add);
else {
int M=L+(R-L)/2;
if (x1<=M) query(lc,L,M,addv[o]+add);
if (x2>M) query(rc,M+1,R,addv[o]+add);
}
}
int main()
{
while(~scanf("%d%d%d",&w,&h,&n))
{
memset(maxv,0,sizeof(maxv));
memset(addv,0,sizeof(addv));
_max=0;
int o,p,pt=0;
memset(ha,0,sizeof(ha));
for (int i=1;i<=n;i++)
{
scanf("%d%d",&o,&p);
ha[++pt].t=o;
ha[pt].pos=p+30001;
ha[pt].st=1;
ha[++pt].t=o+w+1;
ha[pt].pos=p+30001;
ha[pt].st=-1;
}
sort(ha+1,ha+pt+1,cmp);//将全部时间点排序
for (int i=1;i<=pt;i++)
{
x1=ha[i].pos;
x2=ha[i].pos+h;
x2=min(x2,60001);
v=ha[i].st;
update(1,1,60001);//更新点数
if (ha[i].t!=ha[i+1].t||i==pt)//直至同一时间点的全部更新完毕之后才输出
{
x1=1;
x2=60001;
query(1,1,60001,0);
}
}
printf("%d\n",_max);
}
}
[POI 2001+2014acm上海邀请赛]Gold Mine/Beam Cannon 线段树+扫描线
标签:des style http io os ar for sp div
原文地址:http://www.cnblogs.com/gcczhongduan/p/4024420.html