BZOJ 2300 HAOI2011 防线修建 平衡树维护凸包

12 篇文章 0 订阅
10 篇文章 0 订阅

题目大意:给定初始三个点(0,0)(n,0)和(x,y),以及若干其它点,q次询问,每次删除一个点或求一次上凸包长度

平衡树维护凸包……和cash同样的思路为何我时隔2个月后的代码整整短了150行……

平衡树最好用set 链表的每个点存set的迭代器 直接erase很方便

这个题x值的下限和上限都是给定的 所以没有边界讨论 真赞~

一气呵成写出来 调了一小时 尼玛加点我居然加反了0.0

#include<set>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define M 100100
#define INF 1e10
using namespace std;
typedef pair<double,double> point;
struct list;
typedef set< pair<double,list*> >::iterator sit;
struct list{
	list *next,*last;
	point p;
	sit it;
}head,tail;

set< pair<double,list*> >s;
int n,m,q;
int queries[M<<1];
double stack[M];int top;
point a[M];
bool v[M];
double len;

double Distance(const point &p1,const point &p2)
{
	return sqrt( (p1.first-p2.first)*(p1.first-p2.first) + (p1.second-p2.second)*(p1.second-p2.second) );
}

double Get_Slope(const point &p1,const point &p2)
{
	if(p1.first==p2.first)
		return p1.second<p2.second?INF:-INF;
	return (p1.second-p2.second)/(p1.first-p2.first);
}

void Insert(const point &p)
{
	list *secc=s.lower_bound( make_pair(p.first,(list*)0x0) )->second;
	list *pred=secc->last;
	if( Get_Slope(pred->p,p)<Get_Slope(p,secc->p) )
		return ;
	len-=Distance(pred->p,secc->p);
	
	while( pred!=&head && Get_Slope(pred->last->p,pred->p)<Get_Slope(pred->p,p) )
		len-=Distance(pred->last->p,pred->p),s.erase(pred->it),pred=pred->last;
	while( secc!=&tail && Get_Slope(p,secc->p)<Get_Slope(secc->p,secc->next->p) )
		len-=Distance(secc->p,secc->next->p),s.erase(secc->it),secc=secc->next;
	
	len+=Distance(pred->p,p);
	len+=Distance(p,secc->p);
	list *temp=pred->next=secc->last=new list;
	temp->last=pred;
	temp->next=secc;
	temp->p=p;
	temp->it=s.insert( make_pair(p.first,temp) ).first;
}

int main()
{
	int i,x,y,p;
	
	cin>>m>>x>>y>>n;
	for(i=1;i<=n;i++)
		scanf("%lf%lf",&a[i].first,&a[i].second);
	cin>>q;
	for(i=1;i<=q;i++)
	{
		scanf("%d",&p);
		if(p==2)
			queries[i]=-1;
		else
			scanf("%d",&queries[i]),v[queries[i]]=1;
	}
	
	head.next=&tail;
	tail.last=&head;
	head.p=point(0,0);
	head.it=s.insert( make_pair(0,&head) ).first;
	tail.p=point(m,0);
	tail.it=s.insert( make_pair(m,&tail) ).first;
	len=m;
	Insert( point(x,y) );
	
	for(i=1;i<=n;i++)
		if(!v[i])
			Insert(a[i]);
			
	for(i=q;i;i--)
	{
		if(queries[i]==-1)
			stack[++top]=len;
		else
			Insert(a[queries[i]]);
	}
	
	while(top)
		printf("%.2lf\n",stack[top--]);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值