bzoj2300: [HAOI2011]防线修建(set+凸包)

15 篇文章 0 订阅
14 篇文章 0 订阅

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


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

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值