跳到正文

剪贴板

剪贴板 so1nvwzq

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<bits/stdc++.h>
using namespace std;
const int N= 1e5+20  ;

#define ll long long
#define lll __int128
#define lb long double
#define pb push_back
#define mp make_pair
#define min3(xxx,yyy,zzz) min(min(xxx,yyy),zzz)
#define max3(xxx,yyy,zzz) max(max(xxx,yyy),zzz)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(variable,leftrange,rightrange) for(int variable=leftrange;variable<=rightrange;++variable)
#define Rep(variable,leftrange,rightrange) for(int variable=leftrange;variable>=rightrange;--variable)
#define mem(x,y) memset(x,y,sizeof x)
#define sq(x) ((x)*(x))
#define ss stable_sort
#define rds random_shuffle
#define Seed Srand(time(0))
#define rd(p) (rand()%p)
#define nxp next_permutation
#define lowbit(x) (x& -x)
#define gi greater<int>
#define gl greater<ll>
#define vl vector<ll>
#define vi vector<int>
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)
#define Finda(a,siz,b) (lower_bound(a+1,a+siz+1,b)-a)
#define Findv(a,b) (lower_bound(a.begin(),a.end(),b)-a.begin())
#define debug puts("I am still alive")
#define qc(v) v.erase(unique(v.begin(),v.end()),v.end())
#define D double

int n;


struct node{
    D t ,  l , r  ;
    int c ;
    bool operator<(const node &n1) const{
        return t<n1.t ;
    }
} q[N];
#define ls (x<<1)
#define rs (x<<1|1)
#define R Tree[x].r
#define L Tree[x].l
#define mid ((L+R)>>1)
#define C(x) Tree[x].cnt
#define S(x) Tree[x].len
int siz,tot;
D xl,xr,yl,yr;
vector<D> vx,vy ;
struct segement{
    int cnt,l,r;
    D len ;
    void upd(int c)
    {
        cnt+=c;
        if(cnt==1) len = vy[r+1]-vy[l] ;
        if(cnt==0) len = 0 ;
    }
    void init()
    {
        cnt = 0;
        len = 0;
    }

}Tree[N<<2];

void push_up(int x)
{
    if(C(x)==0)
    S(x) = S(ls) + S(rs) ;
    else
    S(x) = vy[R+1] - vy[L] ;
}

void build(int x,int l,int r)
{
    L=l;
    R=r;
    if(L==R) {Tree[x].init(); return ;}
    build(ls,l,mid);
    build(rs,mid+1,r);
    push_up(x);
}

void update(int x,int l,int r,int c)
{
    if(l<=L&&R<=r) {Tree[x].upd(c); push_up(x);  return  ;}
    if(l<=mid)update(ls,l,r,c);
    if(r>mid) update(rs,l,r,c);
    push_up(x);
}

void work()
{
    vx.clear();
    vy.clear();
    tot++;
    if(n==0) exit(0);
    siz = 0;
    rep(i,1,n)
    {cin>>xl>>yl>>xr>>yr; q[++siz] = (node){xl,yl,yr,1} ; q[++siz] = (node){xr,yl,yr,-1}  , vx.push_back(xl) , vy.push_back(yl) , vx.push_back(xr) , vy.push_back(yr); }
    ss(vx.begin(),vx.end());
    ss(vy.begin(),vy.end());
    qc(vx);
    qc(vy);
    ss(q+1,q+1+siz);
    int nw = 1 ;

    build(1,0,(int)vy.size()-2);
    while(q[nw].t==vx[0]&&nw<=siz)
    {        update(1,Findv(vy,q[nw].l),Findv(vy,q[nw].r)-1,q[nw].c) ;
        ++nw;
    }
    D ans = 0;
    for(int i=1;i<vx.size();++i)
    {

        ans += 1ll * S(1) * (vx[i] - vx[i-1]);
        while(q[nw].t==vx[i]&&nw<=siz)
        {
 update(1,Findv(vy,q[nw].l),Findv(vy,q[nw].r)-1,q[nw].c);
        ++nw;
        }
    }
    printf("Test case #%d \nTotal explored area: %.2lf \n",tot,ans);
    puts("");
}
int main()
{
    while(cin>>n) work();
    return  0;
}