bzoj2300 [HAOI2011]防线修建 离线凸包
这个题可以在线做,splay维护凸包的同时维护区间最值线段树,当删除一个点就找跨过这个点的不在凸包上的点的y最值,然后分下去
由于一次确定一个点,所以复杂度还是nlogn的,只是比较难写
如果一个操作非常麻烦,可以考虑对立面,所以就可以考虑倒着加点,就可以直接用splay维护了
注:
引用函数注意对应关系
注意=号
码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int op[100005][2],lll,rrr,sz[100005],ch[100005][2],fu[100005],i,j,n,m,Q,rt,tot,sta[100005],top,dui[100005];
double daan[100005],ans,x[100005],y[100005];
bool wu[100005];
struct dian
{double x,y;int id;
}D[100005];
void up(int o)
{sz[o]=sz[ch[o][0]]+sz[ch[o][1]]+1;
}
void set(int o,int wh,int child)
{ch[o][wh]=child;if(child)fu[child]=o;up(o);
}
int getwh(int o)
{return ch[fu[o]][0]==o?0:1;
}
void rotate(int o)
{int fa=fu[o];int ye=fu[fa];int wh=getwh(o);set(fa,wh,ch[o][wh^1]);set(o,wh^1,fa);fu[o]=ye;if(ye)ch[ye][ch[ye][0]==fa?0:1]=o;
}
void splay(int o,int tar)
{for(;fu[o]!=tar;rotate(o))if(fu[fu[o]]!=tar)getwh(o)==getwh(fu[o])?rotate(fu[o]):rotate(o);if(tar==0)rt=o;
}
void dfs(int o)
{if(o==0)return;cout<<"'"<<x[o]<<" "<<y[o]<<"'"<<"(";dfs(ch[o][0]);cout<<",";dfs(ch[o][1]);cout<<")";
}
void del(int o)
{splay(o,0);if(ch[o][0]==0){rt=ch[o][1];fu[ch[o][1]]=0; }else if(ch[o][1]==0){rt=ch[o][0];fu[ch[o][0]]=0;}else{int p=ch[o][0];while(ch[p][1])p=ch[p][1];set(p,1,ch[o][1]);fu[ch[o][0]]=0;splay(p,0); }
}
int xin(int X,int Y)
{int o=++tot;x[o]=X;y[o]=Y;sz[o]=1;return o;
}
double xl(double ax,double ay,double bx,double by)
{if(ax==bx)return -9999999999999; return (ay-by)/(ax-bx);
}
double jl(double ax,double ay,double bx,double by)
{return sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
}
int jian(int l,int r)
{if(l>r)return 0;int mid=(l+r)>>1,o=++tot;x[o]=D[sta[mid]].x;y[o]=D[sta[mid]].y;set(o,0,jian(l,mid-1));set(o,1,jian(mid+1,r));return o;
}
bool cmp(dian a,dian b)
{if(a.x==b.x)return a.y<b.y;return a.x<b.x;
}
void tubao()
{sort(D+1,D+1+n,cmp);for(i=1;i<=n;i++)dui[D[i].id]=i;int i;for(i=1;i<=n;i++){if(wu[D[i].id])continue;while(top>=2&&xl(D[i].x,D[i].y,D[sta[top-1]].x,D[sta[top-1]].y)>=xl(D[sta[top-1]].x,D[sta[top-1]].y,D[sta[top]].x,D[sta[top]].y))top--;sta[++top]=i; } for(i=1;i<=top;i++) {ans+=jl(D[sta[i]].x,D[sta[i]].y,D[sta[i-1]].x,D[sta[i-1]].y); }rt=jian(1,top);
}
int xiao(double X)
{int o=rt,last=0,ll=0;while(o){last=o;if(x[o]<X&&(x[o]>x[ll]||ll==0))ll=o;if(x[o]<X)o=ch[o][1];else o=ch[o][0];}splay(last,0);return ll;
}
int da(double X)
{int o=rt,last=0,rr=0;while(o){last=o;if(x[o]>X&&(x[o]<x[rr]||rr==0))rr=o;if(x[o]<=X)o=ch[o][1];else o=ch[o][0];}splay(last,0);return rr;
}
int main()
{
scanf("%d",&m);scanf("%lf%lf",&D[0].x,&D[0].y);scanf("%d",&n);for(i=1;i<=n;i++)
{
scanf("%lf%lf",&D[i].x,&D[i].y);
D[i].id=i;
}
D[++n].x=D[0].x;D[n].y=D[0].y;D[n].id=n;
D[++n].x=0;D[n].y=0;D[n].id=n;
D[++n].x=m;D[n].y=0;D[n].id=n;
D[0].x=D[0].y=D[0].id=0;scanf("%d",&Q);for(i=1;i<=Q;i++){scanf("%d",&op[i][0]);if(op[i][0]==1)scanf("%d",&op[i][1]),wu[op[i][1]]=1;}tubao();for(i=Q;i>=1;i--){//dfs(rt);cout<<endl;if(op[i][0]==2)daan[i]=ans;else{int st=dui[op[i][1]];int ll=xiao(D[st].x),rr=da(x[ll]);if(xl(x[ll],y[ll],D[st].x,D[st].y)>xl(x[ll],y[ll],x[rr],y[rr])){ans-=jl(x[ll],y[ll],x[rr],y[rr]);lll=xiao(x[ll]);while(x[lll]<x[ll]&&xl(x[lll],y[lll],D[st].x,D[st].y)>xl(x[lll],y[lll],x[ll],y[ll])){ ans-=jl(x[ll],y[ll],x[lll],y[lll]); del(ll);ll=lll;lll=xiao(x[ll]); } rrr=da(x[rr]);while(x[rrr]>x[rr]&&xl(x[rr],y[rr],D[st].x,D[st].y)<xl(x[rrr],y[rrr],D[st].x,D[st].y)){ ans-=jl(x[rr],y[rr],x[rrr],y[rrr]); del(rr);rr=rrr;rrr=da(x[rr]); } ans+=jl(x[ll],y[ll],D[st].x,D[st].y)+jl(x[rr],y[rr],D[st].x,D[st].y); splay(ll,0);int p=ch[ll][1];if(p==0){set(ll,1,xin(D[st].x,D[st].y));}else{while(ch[p][0])p=ch[p][0];set(p,0,xin(D[st].x,D[st].y));}splay(tot,0);}} }
for(i=1;i<=Q;i++)
if(op[i][0]==2)printf("%.2lf\n",daan[i]);
}
bzoj2300 [HAOI2011]防线修建 离线凸包相关推荐
- 【bzoj2300】【Luogu P2521】 [HAOI2011]防线修建 动态凸包,平衡树,Set
一句话题意:给你一个凸包,每次可以插入一个点或者询问周长. 动态凸包裸题嘛,用\(Set\)实现.最初每个点坐标做乘三处理,便于取初始三角形的重心作为凸包判定原点. #include <bits ...
- [bzoj2300] [HAOI2011]防线修建
Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上层现在还犹豫不决,到底该把哪些城市作为保护 ...
- 【BZOJ2300】[HAOI2011]防线修建 set维护凸包
[BZOJ2300][HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可 ...
- [luogu P2521] [HAOI2011]防线修建
[luogu P2521] [HAOI2011]防线修建 题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国 ...
- Bzoj2300 / 洛谷P2521 [HAOI2011]防线修建
题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上层现在还犹豫不决,到底该把哪些城市作为保护对象呢?又由于 ...
- cogs 547:[HAOI2011] 防线修建
★★★☆ 输入文件:defense.in 输出文件:defense.out 简单对比 时间限制:1 s 内存限制:128 MB 题目描述: 近来A国和B国的矛盾激化,为了预防不测,A国 ...
- P2521 [HAOI2011]防线修建
传送门 一眼看出可以倒着做转为加点维护凸包,然后--然后我就不会了-- 看了一眼题解,大概是这样的,我们先把所有点都读进来,然后按极角排序,也就是说定义点的大小为他们极角的大小(本题里实际上直接按x坐 ...
- [haoi2011]防线修建
动态加点维护凸包. 论STL的熟练运用. #include<cstdio> #include<algorithm> #include<cstring> #inclu ...
- BZOJ 2300: [HAOI2011]防线修建|set维护凸壳
因为只支持插入操作,所以需要倒过来做.. 第一次写维护凸壳的东西-不抄题解..自己YY斜率乱搞(都忘了写叉乘)代码又长常数又大 1A一刻赛艇~ 还是找一个靠谱的的模板吧... #include< ...
最新文章
- 微型激光投影廉价版本
- python 爬虫实例-Python 爬虫:Scrapy 实例(二)
- [HAOI2011]Problem c
- 计算机网络 —— OSI参考模型
- Java 算法 质数的后代
- 将python中的小数直接进位的函数_python保留小数位的三种实现方法
- linux的文件权限前面的东西,linux 文件权限解析
- [转]SQL:JOIN用法
- 动物面部识别技术哪个强?奶牛鸡猪狗绵羊……
- 剑指Offer学习笔记(3)——解决面试题的思路
- 【Docker】04 Docker镜像讲解
- GameofMir__游戏Mod制作【1】
- 民警使用计算机应当遵守哪些保密规定,公安民警保密责任书
- mysql 1.4安装步骤_1.4.1 MySql安装配置
- 通俗易懂的讲讲路由协议
- 电脑连接网线之后怎么给手机开热点
- Python OpenSSL基本操作接口
- MATLAB的画家之旅
- Linux系统(Ubuntu)编写C语言程序
- Apache OJB的分页处理
热门文章
- SpringBoot与SpringCloud集成
- 红橙Darren视频笔记 旋转加载界面
- Android笔记 xml补间动画
- LaTeX TikZ绘图——组合数学中棋盘多项式的画法
- 【李宏毅机器学习】Convolutiona Neural Network 卷积神经网络(p17) 学习笔记
- Ubuntu系统运行darknet出OSError: /libdarknet.so: cannot open shared object file: No such file or directory
- html5 a-z字母排序,vue.js或js实现中文A-Z排序的方法
- python中级_python复习之中级
- 【python基础知识】如何查看pycharm中已经安装的插件
- 前后台交互:跨域以及PHP与Ajax的配合使用