ICPC沈阳 D A Bite of Teyvat

·
#include<bits/stdc++.h>
#define M 100005
#define PI 3.14159265358979323846
#define D long double 
#define eps 1e-11
using namespace std;

D XX=0,YY=0;
D sqr(D x){return x*x;}

struct pt{
    int x,r;
    pt(int X=0,int R=0){x=X;r=R;}
    void rd(){scanf("%d%d",&x,&r);}
    friend bool operator <(pt a,pt b){
        if(a.x!=b.x) return a.x<b.x;
        return a.r<b.r;
    }
    int L(){return x-r;}
    int R(){return x+r;}
    D geth(){
        if(!(x<=XX&&XX<=x+r)) return 0;
        return sqrt(sqr(r)-sqr(XX-x));
    }
}; set<pt> s;

D S(pt now){
    D ans=PI;
    return ans*now.r*now.r;
}

D S(pt a,pt b){///!!!
    if(b<a) swap(a,b);
    if(a.x+a.r<b.x-b.r+eps) return 0;
    D A=a.r,B=b.r,C=b.x-a.x;
    D P=(A+B+C)/2.;
    D S2=sqrt(P*(P-A)*(P-B)*(P-C));
    D cosA= (sqr(A)+sqr(C)-sqr(B))/(2*A*C);
    D cosB= (sqr(B)+sqr(C)-sqr(A))/(2*B*C);
    D sinA=sqrt(1-sqr(cosA));
    D sinB=sqrt(1-sqr(cosB));
    D sitaA=acos(cosA);
    D sitaB=acos(cosB);
    D sA=sitaA*sqr(A)*0.5;
    D sB=sitaB*sqr(B)*0.5;
    XX=a.x+A*cosA;
    YY=A*sinA;
    return 2*(sA+sB-S2);
}

bool in(pt son,pt fa){
    return fa.L()<=son.L()&&son.R()<=fa.R();
}

bool in(pt l,pt r,pt son){
    if(S(l,r)==0) return 0;
    int h=son.geth();
    return h<=YY+eps;//eps!!
}

int main(){
    s.insert(pt(-M,0));
    s.insert(pt(M,0));
    int n; cin>>n;
    D ans=0;
    while(n--){
        pt now; now.rd();
        set<pt>::iterator e,itr=s.upper_bound(now);
        set<pt>::iterator itl=itr; itl--;
        bool isIn=0;
        if(in(now,*itr)) isIn=1;
        if(in(now,*itl)) isIn=1;
        if(in(*itl,*itr,now)) isIn=1;
        if(isIn){
            printf("%.10lf\n",ans);
            continue;
        }
        ans+=S(*itl,*itr);
        while(in(*itr,now)){
            e=itr++;
            ans-=S(*e)-S(*e,*itr);
            s.erase(e);
        }
        while(in(*itl,now)){
            e=itl--;
            ans-=S(*e)-S(*e,*itl);
            s.erase(e);
        }
        ans+=S(now)-S(now,*itl)-S(now,*itr)+S(*itl,*itr);
        s.insert(now);
        printf("%.10Lf\n",ans);
    }
}

 

posted @ 2022-11-05 17:16  AlphaInf  阅读(85)  评论(0编辑  收藏  举报