题目链接: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. Codeforces Round #533 (Div. 2) A. Salem and Sticks(暴力)

    A. Salem and Sticks time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. iOS保持App真后台运行

    https://www.jianshu.com/p/d466f2da0d33 在我看来,苹果系统与安卓系统最直观的区别就是后台处理方式了吧,安卓手机一旦开启了很多app放到后台,即使前台什么也不做,就 ...

  3. python中的Init方法, new 方法 call 方法

    new 方法实现单列模式思考 class Single: _single = None _single_only = None def __init__(self, value): self.v = ...

  4. centos 7 network.service control process exited

    一.service network restart 出错 问题描述: vmware 12 下centos 7 网络模式,NAT 昨晚作者打算更新自己虚拟机python,发现没网络ping www.ba ...

  5. Python_面向对象基础

    概念 类 一类抽象的事物,是描述了一类事物有哪些属性或者行为,但不是具体——模子. 实例 一个依托于类的规范存在的,被赋予了具体属性值的实际存在的物体. 对象 就是实例,实例的另外一个名称,相当于别名 ...

  6. C#中使用打印日志

    在日常的工作中经常需要日志,这样能够很容易定位到代码中的一些错误,.Net中有自带的日志接口.并没有仔细去研究,这里是我自己写的日志接口,记录下来以便以后用到,根据时间打印相关的日志文件,代码如下: ...

  7. vue上传图片到服务器

    https://blog.csdn.net/qq_29712995/article/details/78839093(copy) HTML代码: <input accept="imag ...

  8. 大白跟着“菜鸟”学node——同名事件

    若存在两个同名事件,触发事件时,两个事件监听器的回调函数会被按次序先后调用. 实例来自菜鸟教程: var events=require('events'); var emitter=new event ...

  9. java学习之—使用栈实现字符串数字四则运算

    /** * 使用栈存储后缀表达式 * Create by Administrator * 2018/6/13 0013 * 下午 2:25 **/ public class StackX { priv ...

  10. VS Code & MacOS & Zsh

    VS Code & MacOS & Zsh https://code.visualstudio.com/docs/setup/mac solution OK bug $ cat .zs ...