bzoj2300#2300. [HAOI2011]防线修建

题解:带删点的维护凸包,1.删点2.查询凸包周长
题解:倒着做就成了带加点的维护凸包,加点时维护一下周长就没了

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
//#define ls l,m,rt<<1
//#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;

const ull ba=233;
const db eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=200000+10,maxn=1000000+10,inf=0x3f3f3f3f;

struct node{
    ll x,y;
    node(){}
    node(ld _x,ld _y){x=_x,y=_y;}
    bool operator <(const node&rhs)const{
        return x<rhs.x||(x==rhs.x&&y<rhs.y);
    }
};
#define sqr(a) (a)*(a)
db dis(node a,node b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
db ans=0;
bool ok=0;
struct hull:set<node>{
    bool bad(iterator it)
    {
        if(it==begin()||next(it)==end())return 0;
        return (it->y-prev(it)->y)*(next(it)->x-it->x)<(next(it)->y-it->y)*(it->x-prev(it)->x);
    }
    void update(node x)
    {
        if(find(x)!=end())return ;
        iterator it=insert(x).fi;
        if(bad(it)){erase(it);return ;}
        if(it!=begin())ans+=dis(*it,*prev(it));
        if(next(it)!=end())ans+=dis(*it,*next(it));
        if(it!=begin()&&next(it)!=end())ans-=dis(*prev(it),*next(it));
        while(it!=begin()&&bad(prev(it)))
        {
            if(prev(it)!=begin())
            {
                ans-=dis(*prev(it),*prev(prev(it)));
                ans+=dis(*prev(prev(it)),*it);
            }
            ans-=dis(*it,*prev(it));
            erase(prev(it));
        }
        while(next(it)!=end()&&bad(next(it)))
        {
            if(next(next(it))!=end())
            {
                ans-=dis(*next(it),*next(next(it)));
                ans+=dis(*next(next(it)),*it);
            }
            ans-=dis(*it,*next(it));
            erase(next(it));
        }
    }
}h;
pii p[N];
node a[N];
db res[N];
bool ban[N];
int main()
{
    int n,x,y;scanf("%d%d%d",&n,&x,&y);
    h.update(node(0,0));h.update(node(x,y));h.update(node(n,0));
    int m;scanf("%d",&m);
    for(int i=1;i<=m;i++)scanf("%lld%lld",&a[i].x,&a[i].y);
    int q;scanf("%d",&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&p[i].fi);
        if(p[i].fi==1)scanf("%d",&p[i].se),ban[p[i].se]=1;
    }
    for(int i=1;i<=m;i++)if(!ban[i])h.update(a[i]);
//    printf("%f %f\n",ans,2.0*sqrt(5));
    for(int i=q;i>=1;i--)
    {
        if(p[i].fi==2)res[i]=ans;
        else h.update(a[p[i].se]);//,printf("%lld %lld--\n",a[p[i].se].x,a[p[i].se].y);
    }
    for(int i=1;i<=q;i++)if(p[i].fi==2)printf("%.2f\n",res[i]);
    return 0;
}
/********************

********************/
posted @ 2019-04-04 20:18  walfy  阅读(167)  评论(0编辑  收藏  举报