顺便把1255也过了~~无压力~

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
const int maxn=2222;
struct pp                                                                                                                   
{
    double l;
    double r;
    double h; 
    int d;
    pp(){}
    pp (double a,double b,double c,int dd) : l(a) , r(b) , h(c) , d(dd) {};
    bool operator < (const pp &cmp) const 
    {
return h < cmp.h;                     
}
}px;
struct dd
{
    double x;
    int b;
    dd(){}
    dd(double a)
    {
        x=a;
        b=0; 
    }
    dd(double a,int bb) 
    {
        x=a;
        b=bb;
    }
    bool operator < (const dd &cmp) const
    {
        return x < cmp.x;
    }
    bool operator == (const dd &cmp) const 
    {
        return x==cmp.x;
    }
}dx;
double sum[maxn<<2];
int add[maxn<<2];
int lend[maxn<<2];
int rend[maxn<<2];
vector<double>vx;
vector<double>v;
set<dd> sx;
set<dd>::iterator si;
vector<pp>vp;
double a,b,c,d,t,total,dps;
int n,temp,tt,lstart,rstart,TT;
int find(double x)
{
    si=sx.find(x);
    return si->b;    
}
void push_up(int root)
{
    sum[root]=sum[root<<1]+sum[root<<1|1]; 
    return ;          
}
void build(int l,int r,int root=1)
{
    lend[root]=l;
    rend[root]=r;
    int mid=(r+l)>>1;
    if(r-l==1)
    {
        sum[root]=v[r]-v[l];
        return ;    
    }     
    else
    {
        build(l,mid,root<<1);
        build(mid,r,root<<1|1);
        push_up(root);
        return ;
    }              
}
void update(int l,int r,int d,int root=1)
{
    if(l<=lend[root] && r>=rend[root]) 
    {
        add[root]+=d;
        return ;
    }   
    else
    {
        if(l<rend[root<<1] && r>lend[root<<1])
        {
            update(l,r,d,root<<1);
        }
        if(r>lend[root<<1|1] && l<rend[root<<1|1])
        {
            update(l,r,d,root<<1|1);
        }
        return ;
    }
}
void query(int now,int root=1)
{
    if(add[root]+now>=2)
    {
        dps+=sum[root];
        return ;
    }    
    else if(add[root]+now==0)
    {
        
        if(rend[root<<1]-lend[root<<1]>=1)
        {
            query(0,root<<1);
        }
        if(rend[root<<1|1]-lend[root<<1|1]>=1)
        {
            query(0,root<<1|1);
        }
        return ;
    }
    else if(add[root]+now==1)
    {
        if(rend[root<<1]-lend[root<<1]>=1)
        {
            query(1,root<<1);
        }
        if(rend[root<<1|1]-lend[root<<1|1]>=1)
        {
            query(1,root<<1|1);
        }
        return ;
    }
}
int main()
{
    cin>>TT;
    for(int e=1;e<=TT;e++)
    {
        cin>>n;
        memset(sum,0,sizeof(sum));
        memset(add,0,sizeof(add));
        total=0.0;
        dps=0.0;
        sx.clear();
        vx.clear();
        vp.clear();
        v.clear();   
        v.push_back(0.0);
        for(int i=1;i<=n;i++)
        {
            scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
            vx.push_back(a);
            vx.push_back(c);
            px=pp(a,c,b,1);
            vp.push_back(px);
            px=pp(a,c,d,-1);
            vp.push_back(px);
        }                  
        sort(vp.begin(),vp.end());
        sort(vx.begin(),vx.end());
        temp=1;
        t=-0.1;
        for(int i=0;i<vx.size();i++)
        {
            if(vx[i]!=t)
            {
                dx=dd(vx[i],temp);
                temp++; 
                t=vx[i]; 
                v.push_back(vx[i]);
                sx.insert(dx);  
            }        
            else
            {
                continue;   
            }
        }  
        build(1,v.size()-1);
        t=vp[0].h;
        for(int i=0;i<vp.size();)
        {
             
            if(vp[i].h==t)
            {                       
                update(find(vp[i].l),find(vp[i].r),vp[i].d);
                i++;
            }      
            else
            {
                dps=0;
                query(0);
                total+=dps*(vp[i].h - t);
                t=vp[i].h;
            }
        }  
        //<<setiosflags(ios::fixed)<<setprecision(2)<<total<<endl<<endl;
        printf("%.2lf\n",total);
    }    
    return 0;
}
390ms~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值