题目链接: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. PHP实用代码片段(一)

    1. 发送 SMS 在开发 Web 或者移动应用的时候,经常会遇到需要发送 SMS 给用户,或者因为登录原因,或者是为了发送信息.下面的 PHP 代码就实现了发送 SMS 的功能. 为了使用任何的语言 ...

  2. 把玩Alpine linux(二):APK包管理器

    导读 Alpine Linux非常精简,开机内存占用也在二三十兆大,没有拆箱即用,就需要我们自己去做一些了解和配置 Alpine Linux的优劣 优势 Alpine Linux的Docker镜像特点 ...

  3. No enclosing instance of type is accessible. Must qualify the allocation with an enclosing instance of type LeadRestControllerTest (e.g. x.new A() where x is an instance of ).

    java - No enclosing instance is accessible. Must qualify the allocation with an enclosing instance o ...

  4. MySQL 5.7 Reference Manual :: 4.5.4 mysqldump & mysql — Database Backup & Restore Program

    MySQL :: MySQL 5.7 Reference Manual :: 4.5.4 mysqldump — A Database Backup Programhttps://dev.mysql. ...

  5. c++ 单引号"字符串" 用法

    __int64 flag; //赋值超过4字节,编译错误 //flag = 'ABCDE'; //低于4字节,高位补 0 //flag = 'BCDE'; flag = 'A' << 24 ...

  6. python3 网页下拉框和悬浮框操作基础汇总

    #悬浮定位操作 from selenium.webdrier import ActionChains #浏览器实例化 #定位移动的位置赋给一个参数 ActionChains(浏览器).move_to_ ...

  7. PropertyChangeSupport 监听器模式的应用

    PropertyChangeSupport 类实现的监听器功能 ,它是java jdk自带的一个类,用于监听某个对象属性的改变来触发相应信息,具体看代码介绍 import java.beans.Pro ...

  8. STL 序列容器

    转自时习之 STL中大家最耳熟能详的可能就是容器,容器大致可以分为两类,序列型容器(SequenceContainer)和关联型容器(AssociativeContainer)这里介绍STL中的各种序 ...

  9. ActiveMQ入门案例-生产者代码实现

    <–start–> 使用Java程序操作ActiveMQ生产消息,代码的复杂度较高,但也没有默写下来的必要. 开发ActiveMQ首先需要导入activemq-all.jar包,如果是ma ...

  10. java学习之—队列

    /** * 队列 * Create by Administrator * 2018/6/11 0011 * 下午 3:27 **/ public class Queue { private int m ...