因为只支持插入操作,所以需要倒过来做..
第一次写维护凸壳的东西…不抄题解..自己YY斜率乱搞(都忘了写叉乘)代码又长常数又大
1A一刻赛艇~
还是找一个靠谱的的模板吧...
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<iostream>
#define N 500050
#define inf 2000000000
using namespace std;
int sc()
{
int i=0,f=1; char c=getchar();
while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9')i=i*10+c-'0',c=getchar();
return i*f;
}
set<pair<int,int> >st;
double ans,A[100002];
int a[100002],b[100002],d[100002];
int n,fx,fy,top,m,q;
bool c[100002];
double kk(int x,int y){return sqrt((double)x*x+y*y);}
double cal(int x,int y)
{
if(!x)return inf;
return (double)y/x;
}
void add(int x,int y)
{
set<pair<int,int> >::iterator it,e;
it=st.lower_bound(make_pair(x,y));
if((*it).first==x)return;
bool flag=0;
while(++it!=st.end())
{
pair<int,int> b=*it,a=*--it;
double l1=cal(a.first-x,a.second-y);
double l2=cal(b.first-x,b.second-y);
if(l2<l1)break;
if(!flag)
{
pair<int,int> c=*--it;it++;
ans-=kk(c.first-a.first,c.second-a.second);
flag=1;
}
ans-=kk(a.first-b.first,a.second-b.second);
e=it,++it;
st.erase(e);
}
it=st.lower_bound(make_pair(x,y));it--;
while(it!=st.begin())
{
pair<int,int> a=*it,b=*--it;
double l1=cal(a.first-x,a.second-y);
double l2=cal(b.first-x,b.second-y);
if(l2>l1)break;
if(!flag)
{
it++;it++;
pair<int,int> c=*it;it--;it--;
ans-=kk(c.first-a.first,c.second-a.second);
flag=1;
}
ans-=kk(a.first-b.first,a.second-b.second);
e=it,st.erase(++e);
}
if(flag)
{
it=st.lower_bound(make_pair(x,y));
ans+=kk((*it).first-x,(*it).second-y);
it--;
ans+=kk((*it).first-x,(*it).second-y);
st.insert(make_pair(x,y));
}
else
{
it=st.lower_bound(make_pair(x,y));
pair<int,int> a=*it,b=*--it;
double l1=cal(a.first-x,a.second-y);
double l2=cal(b.first-x,b.second-y);
if(l1<l2)
{
ans-=kk(a.first-b.first,a.second-b.second);
ans+=kk((*it).first-x,(*it).second-y);
it++;
ans+=kk((*it).first-x,(*it).second-y);
st.insert(make_pair(x,y));
}
}
}
int main()
{
n=sc(),fx=sc(),fy=sc(),m=sc();
for(int i=1;i<=m;i++)
a[i]=sc(),b[i]=sc();
q=sc();
for(int i=1;i<=q;i++)
{
d[i]=sc();
if(d[i]==1)c[d[i]=sc()]=1;
else d[i]=0;
}
st.insert(make_pair(0,0));
st.insert(make_pair(n,0));
st.insert(make_pair(fx,fy));
ans=kk(fx,fy)+kk(fx-n,fy);
for(int i=1;i<=m;i++)
if(!c[i])add(a[i],b[i]);
for(int i=q;i;i--)
{
if(!d[i])A[++top]=ans;
else add(a[d[i]],b[d[i]]);
}
while(top)printf("%.2lf\n",A[top--]);
return 0;
}