传送门

题意:动态维护凸包周长。


思路:

这篇求面积的吧反正都是一个套路。

代码:

#include<bits/stdc++.h>
#define int long long
#define ri register int
using namespace std;
inline int read(){
    int ans=0;
    bool f=1;
    char ch=getchar();
    while(!isdigit(ch))f^=(ch=='-'),ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return f?ans:-ans;
}
typedef long long ll;
const int N=2e5+5;
struct pot{
    ll x,y;
    double ang;
    pot(ll _x=0,ll _y=0):x(_x),y(_y){}
    pot(ll _x,ll _y,double _ang):x(_x),y(_y),ang(_ang){}
    friend inline pot operator+(const pot&a,const pot&b){return pot(a.x+b.x,a.y+b.y);}
    friend inline pot operator-(const pot&a,const pot&b){return pot(a.x-b.x,a.y-b.y);}
    friend inline ll operator^(const pot&a,const pot&b){return a.x*b.y-a.y*b.x;}
    friend inline bool operator<(const pot&a,const pot&b){return a.ang<b.ang;}
    inline double mod(){return sqrt((double)(x*x+y*y));}
}a[N];
inline double dist(const pot&a,const pot&b){return (a-b).mod();}
set<pot>S;
typedef set<pot>::iterator It;
double sum=0;
int n,m;
bool vis[N];
struct qry{int op,id;}ask[N];
vector<double>ans;
inline pot Pre(const pot&x){
    if(S.count(x)>0)return x;
    It it=S.lower_bound(x);
    if(it==S.begin())it=S.end();
    return *--it;
}
inline pot Suf(const pot&x){
    It it=S.upper_bound(x);
    if(it==S.end())it=S.begin();
    return *it;
}
inline bool in(const pot&x){
    pot suf=Suf(x),pre=Pre(x);
    return ((x-pre)^(suf-pre))<=0;
}
inline void insert(const pot&x){
    if(in(x))return;
    pot suf=Suf(x),pre=Pre(x);
    sum-=dist(suf,pre);
    while(1){
        pot p1=Pre(x),p2;
        S.erase(p1);
        p2=Pre(x);
        if(((x-p1)^(p2-p1))>=0){S.insert(p1);break;}
        sum-=dist(p1,p2);
    }
    while(1){
        pot p1=Suf(x),p2;
        S.erase(p1);
        p2=Suf(x);
        if(((x-p1)^(p2-p1))<=0){S.insert(p1);break;}
        sum-=dist(p1,p2);
    }
    sum+=dist(Pre(x),x),sum+=dist(Suf(x),x);
    S.insert(x);
}
signed main(){
    srand(time(NULL));
    int xxx=rand(),yyy=rand(),zzz=rand(),ttt=xxx+yyy+zzz;
    a[1]=pot(0,0),a[2]=pot(read(),0),a[3].x=read(),a[3].y=read();
    double X,Y;
    X=(double)(a[1].x*xxx+a[2].x*yyy+a[3].x*zzz)/ttt;
    Y=(double)(a[1].y*xxx+a[2].y*yyy+a[3].y*zzz)/ttt;
    for(ri i=1;i<=3;++i)S.insert(pot(a[i].x,a[i].y,atan2(Y-a[i].y,X-a[i].x)));
    sum=dist(a[2],a[3])+dist(a[3],a[1]);
    n=read();
    for(ri i=1;i<=n;++i)a[i].x=read(),a[i].y=read();
    m=read();
    for(ri i=1;i<=m;++i){
        ask[i].op=read();
        if(ask[i].op==1)vis[ask[i].id=read()]=1;
    }
    for(ri i=1;i<=n;++i)if(!vis[i])insert(pot(a[i].x,a[i].y,atan2(Y-a[i].y,X-a[i].x)));
    for(ri i=m,id;i;--i){
        if(ask[i].op==1){
            id=ask[i].id;
            insert(pot(a[id].x,a[id].y,atan2(Y-a[id].y,X-a[id].x)));
        }
        else ans.push_back(sum);
    }
    for(ri i=ans.size()-1;~i;--i)printf("%.2lf\n",ans[i]);
    return 0;
}


2019.02.21 bzoj2300: [HAOI2011]防线修建(set+凸包)的更多相关文章

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

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

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

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

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

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

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

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

  5. BZOJ2300: [HAOI2011]防线修建

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2300 (我只是在发以前写过的题.. 因为题目没说强制在线,所以离线乱搞就可以了.先把点删掉然后 ...

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

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

  7. 2019.02.21 bzoj5317: [Jsoi2018]部落战争(凸包+Minkowski和)

    传送门 题意:qqq次询问把一个凸包整体加一个向量(x,y)(x,y)(x,y)之后是否与另外一个凸包相交. 思路:转化一下发现只要会求A+B={v⃗=a⃗+b⃗∣a⃗∈A,b⃗∈B}A+B=\{\v ...

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

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

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

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

随机推荐

  1. .NET自动化测试工具链:Selenium+NUnit+ExtentReport

    Selenium可以执行UI的交互,ExtentReport用来生成测试报告,NUnit是我熟悉的基础测试框架,当然你也可以用MSTest.Xunit来代替.Selenium.NUnit没啥好讲的,网 ...

  2. 03-封装Response响应

    package com.day5; import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputSt ...

  3. python常见循环练习

    第一题:求5的阶乘 # 方法1,递归 def jc(num): if num == 1: return 1 else: return num*jc(num-1) print(jc(5)) # 方法2, ...

  4. JVM 垃圾回收GC Roots Tracing

    1.跟搜索算法: JVM中对内存进行回收时,需要判断对象是否仍在使用中,可以通过GC Roots Tracing辨别. 定义: 通过一系列名为”GCRoots”的对象作为起始点,从这个节点向下搜索,搜 ...

  5. 一个linux bbr存在的调用顺序bug

    最近跟踪bbr的状态转换的代码,发现一个问题: [,min_rtt_us=,full_bw=,cycle_idx=,pacing_gain=,cwnd_gain=,rtt_cnt= [,min_rtt ...

  6. 解决no module named ipykernel_launcher

    解决no module named ipykernel_launcher 最近开hydrogen的时候,提示no module named ipykernel_launcher. 记得以前解决过这个问 ...

  7. 权限控制框架---shiro入门

    1.shiro控制权限的两种思想:粗粒度url级别,细粒度方法级别 2.shiro执行流程简介 3.案例 3.1shiro控制用户登录实现,登录其实就是shiro中的认证. (1)配置web.xml( ...

  8. Ubuntu输入命令无效的问题

    https://blog.csdn.net/u014797226/article/details/80800550?utm_source=blogxgwz2 Ubuntu启动时输入密码后,一直停留在登 ...

  9. ubuntu系统中安装eclipse

    具体可以看这篇博文 .https://www.cnblogs.com/sanduo1314/articles/5137090.html 然后再/usr/share/applications中找到ecl ...

  10. wiredtiger--初学数据恢复

    启动mongodb是failed,日志如下 1.解压wirdtiger包 tar -vxf wiredtiger-3.1.0.tar.bz2 -C /home/wiredtiger/ 2.安装snap ...