题目链接:P2521 [HAOI2011]防线修建

题意:给定点集

每次有两种操作:

1. 删除一个点 (除开(0, 0), (n, 0), 与指定首都(x, y))

2. 询问上凸包长度

至于为什么是上凸包 “三角形任意两边之和大于第三边”就可以证

我们的套路不包括只做删除的在线凸包问题 所以把询问逆序操作

根据套路 只有插入操作的 对答案贡献不独立的凸包问题 我们使用平衡树维护

其实只用求前驱后继 所以蒟蒻就偷懒用了STL的set

一开始构造最后删完的点集的凸包

每次插入一个点时

如果它在当前凸包内部或凸包上 那么不影响答案 直接忽略

如果在外部 从近到远询问它前面的点 类似于Andrew一开始插入点的做法

再从近到远询问它后面的点 做法同样

记得维护答案

 #include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
using namespace std;
const int N = 1e5 + ;
const int Q = 2e5 + ;
const double eps = 1e-;
struct Node{
int id;
double x, y;
}node[N], stk[N], nl;
set<Node> st;
int rf[N];
struct Query{
int x, y;
}q[Q];
double anss[N];
int as;
int n, m, cx, cy, qs;
int top;
double ans;
bool ask[N]; Node operator - (const Node& x, const Node& y){
return (Node){, x.x - y.x, x.y - y.y};
} bool operator < (const Node& x, const Node& y){
if(fabs(x.x - y.x) < eps) return x.y + eps < y.y;
return x.x + eps < y.x;
} inline double cross(Node x, Node y){
return x.x * y.y - x.y * y.x;
} inline double dis(Node x, Node y){
return sqrt((y.x - x.x) * (y.x - x.x)
+ (y.y - x.y) * (y.y - x.y));
} Node next(Node x){
set<Node> :: iterator it;
it = st.upper_bound(x);
if(it != st.end()) return *it;
else return nl;
} Node prev(Node x){
set<Node> :: iterator it;
it = st.lower_bound(x);
if(it != st.begin()) return *(--it);
else return nl;
} inline void Andrew(){
top = ;
for(int i = ; i <= m; i++) if(!ask[node[i].id]){
while(top > && cross(stk[top] - stk[top - ], node[i] - stk[top]) > eps){
ans -= dis(stk[top], stk[top - ]);
top--;
}
stk[++top] = node[i];
if(top > ) ans += dis(stk[top], stk[top - ]);
}
for(int i = ; i <= top; i++)
st.insert(stk[i]);
} inline void init(){
scanf("%d%d%d%d", &n, &cx, &cy, &m);
for(int i = ; i <= m; i++){
scanf("%lf%lf", &node[i].x, &node[i].y);
node[i].id = i;
}
++m; node[m] = (Node){m, , };
++m; node[m] = (Node){m, 1.0 * n, };
++m; node[m] = (Node){m, 1.0 * cx, 1.0 * cy};
sort(node + , node + m + );
for(int i = ; i <= m; i++){
rf[node[i].id] = i;
}
scanf("%d", &qs);
for(int i = ; i <= qs; i++){
scanf("%d", &q[i].x);
if(q[i].x == ){
scanf("%d", &q[i].y);
ask[q[i].y] = ;
}
else {
as++;
q[i].y = as;
}
}
Andrew();
} inline void ins(Node x){
Node pre = prev(x), pp;
Node nxt = next(x), nn;
if(cross(x - pre, nxt - x) > eps){
return ;
}
ans -= dis(pre, nxt);
while(pre.id != m - ){
pp = prev(pre);
if(cross(pre - pp, x - pre) > eps){
ans -= dis(pp, pre);
st.erase(pre);
pre = pp;
}
else break;
}
ans += dis(pre, x);
while(nxt.id != m - ){
nn = next(nxt);
if(cross(nxt - x, nn - nxt) > eps){
ans -= dis(nxt, nn);
st.erase(nxt);
nxt = nn;
}
else break;
}
ans += dis(x, nxt);
st.insert(x);
} int main(){
init();
for(int i = qs; i >= ; i--)
if(q[i].x == )
ins(node[rf[q[i].y]]);
else
anss[q[i].y] = ans;
for(int i = ; i <= as; i++) printf("%.2lf\n", anss[i]);
return ;
}

附上代码:

P2521 [HAOI2011]防线修建的更多相关文章

  1. [luogu P2521] [HAOI2011]防线修建

    [luogu P2521] [HAOI2011]防线修建 题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国 ...

  2. 【题解】P2521 [HAOI2011]防线修建(动态凸包)

    [题解]P2521 [HAOI2011]防线修建(动态凸包) 凸包是易插入不好删除的东西,按照剧情所以我们时光倒流 然后问题就是维护凸包的周长,支持加入 本来很简单,但是计算几何就是一些小地方经验不足 ...

  3. Bzoj2300 / 洛谷P2521 [HAOI2011]防线修建

    题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上层现在还犹豫不决,到底该把哪些城市作为保护对象呢?又由于 ...

  4. 【BZOJ 2300】 2300: [HAOI2011]防线修建 (动态凸包+set)

    2300: [HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上 ...

  5. BZOJ 2300: [HAOI2011]防线修建( 动态凸包 )

    离线然后倒着做就变成了支持加点的动态凸包...用平衡树维护上凸壳...时间复杂度O(NlogN) --------------------------------------------------- ...

  6. bzoj千题计划236:bzoj2300: [HAOI2011]防线修建

    http://www.lydsy.com/JudgeOnline/problem.php?id=2300 维护动态凸包,人懒用的set 用叉积判断,不要用斜率 #include<set> ...

  7. 【BZOJ2300】[HAOI2011]防线修建 set维护凸包

    [BZOJ2300][HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可 ...

  8. 【bzoj2300】【Luogu P2521】 [HAOI2011]防线修建 动态凸包,平衡树,Set

    一句话题意:给你一个凸包,每次可以插入一个点或者询问周长. 动态凸包裸题嘛,用\(Set\)实现.最初每个点坐标做乘三处理,便于取初始三角形的重心作为凸包判定原点. #include <bits ...

  9. BZOJ2300[HAOI2011]防线修建——非旋转treap+凸包(平衡树动态维护凸包)

    题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上层现在还犹豫不决,到底该把哪些城市作为保护对象呢?又由于 ...

随机推荐

  1. 设计模式——MVC MVP MVVM

    了解到Vue是MVVM前端框架, 中午就研究了一下MVVM,但要从MVC开始说起: M(Model):模型,提供数据: V(View):视图,负责显示: C(Controller):控制器,负责逻辑处 ...

  2. MySQL和Oracle的区别

    由于SQL Server不常用,所以这里只针对MySQL数据库和Oracle数据库的区别 (1) 对事务的提交    MySQL默认是自动提交,而Oracle默认不自动提交,需要用户手动提交,需要在写 ...

  3. SOAP UI-----测webservice接口

    webservice的请求报文和返回报文都是xml格式的. 使用soapui.storm对webservice接口进行测试,postman无法测. http://www.webxml.com.cn/W ...

  4. shell脚本使用记录一:操作文件

    一,连接远程数据库(保证在服务器上能使用mysql命令行,至少要安装mysql客户端) #!/bin/bash HOSTNAME="ip" PORT=" USERNAME ...

  5. 解决linux用户切换失败 su:execute /usr/bin 没有权限

    问题描述: 回宿舍前,在root用户中安装fish,并修改其shell为fish.回宿舍之后,在图形界面用root用户进行登陆,莫名其妙登陆失败.没有任何提示信息,直接回到登陆界面.用非root用户登 ...

  6. linux系统下MySQL表名区分大小写问题

    linux系统下MySQL表名区分大小写问题 https://www.cnblogs.com/jun1019/p/7073227.html [mysqld] lower_case_table_name ...

  7. MySQL 5.7默认ONLY_FULL_GROUP_BY语义介绍

    mysql 5.7版本 出现 ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre ...

  8. asp.net mvc Areas 母版页动态获取数据进行渲染

    经常需要将一些通用的页面元素抽离出来制作成母版页,但是这里的元素一般都是些基本元素,即不需要 进行后台数据交换的基本数据,但是对于一些需要通过后台查询的数据,我们应该怎么传递给前台的母版页呢 这里描述 ...

  9. Python + selenium + pycharm 环境部署细节 和selenium、Jenkins简单介绍

    一.测试体系:Python + selenium + pycharm + Jenkins/docker 环境搭建: 1.安装python 3.4/3.5 2/3.6/ 3.7 2.配置环境变量 3.p ...

  10. React Native之倒计时组件的实现(ios android)

    React Native之倒计时组件的实现(ios android) 一,需求分析 1,app需实现类似于淘宝的活动倒计时,并在倒计时结束时,活动也结束. 2,实现订单倒计时,并在倒计时结束时,订单关 ...