离线然后把所有的操作倒过来,这样就像星球大战一样,删点变成加点,动态用平衡树维护凸包就好了。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<set>
#include<cmath>
#define maxn 200021
using namespace std;
struct P{
double x,y;
P(double a=0,double b=0):x(a),y(b){}
bool operator<(const P& b)const{return x==b.x?y<b.y:x<b.x;}
}p[maxn];
typedef P vec;
double operator*(P a,P b){return a.x*b.y-a.y*b.x;}
vec operator-(P a,P b){return vec(a.x-b.x,a.y-b.y);}
struct oper{int pos,t,id;}op[maxn];
set<P>s;
int n,sx,sy,m,Q,vis[maxn],cnt;
double ans,Ans[maxn];
double dis(P a,P b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
void insert(P x){
set<P>::iterator l,r,t;
r=s.lower_bound(x);l=r;l--;
if((*r-*l)*(x-*l)<0)return;
ans+=dis(x,*l)+dis(x,*r)-dis(*r,*l);
while(1){
if(l==s.begin())break;
t=l;t--;
if((*l-*t)*(x-*l)<0)break;
ans+=dis(x,*t)-(dis(x,*l)+dis(*l,*t));
s.erase(l);l=t;
}
while(1){
t=r;t++;
if(t==s.end())break;
if((*r-x)*(*t-*r)<0)break;
ans+=dis(*t,x)-(dis(x,*r)+dis(*r,*t));
s.erase(r);r=t;
}s.insert(x);
}
int main(){
scanf("%d%d%d",&n,&sx,&sy);
s.insert(P(0,0)),s.insert(P(n,0)),s.insert(P(sx,sy));
ans+=dis(P(0,0),P(sx,sy))+dis(P(sx,sy),P(n,0));
scanf("%d",&m);
for(int i=1;i<=m;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
scanf("%d",&Q);
for(int i=1;i<=Q;i++){
scanf("%d",&op[i].pos);
if(op[i].pos==1)scanf("%d",&op[i].id),vis[op[i].id]=1;
}
for(int i=1;i<=m;i++)if(!vis[i])insert(p[i]);
for(int i=Q;i>=1;i--){
if(op[i].pos==1)insert(p[op[i].id]);
else Ans[++cnt]=ans;
}
for(int i=cnt;i>=1;i--)printf("%.2lf\n",Ans[i]);
return 0;
}