调!!!
查看原帖
调!!!
553871
JMxxxx楼主2025/7/25 11:06
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6;
struct node{
    int l,r;
    int len;
    int sum;
};
node tree[N<<2];
int pt[N];
void update(int x)
{
    if(tree[x].sum)
        tree[x].len=pt[tree[x].r+1]-pt[tree[x].l];
    else
        tree[x].len=tree[x<<1].len+tree[x<<1|1].len;
}
struct in{
    int l,r,h;
    int mark;
    bool operator<(const in p)const{
        if(h==p.h)return mark>p.mark;
        else return h < p.h;
    }
};
in arr[N];
void build(int x,int l,int r)
{
    tree[x].l=l,tree[x].r=r;
    tree[x].len=0;tree[x].sum=0;
    if(l==r)return ;
    int mid=l+r>>1;
    build(x<<1,l,mid);
    build(x<<1|1,mid+1,r);
    return ;
}
void change(int x,int l,int r,int c)
{
    if (pt[tree[x].r + 1] <= l||r<= pt[tree[x].l]) return;
    if(l<=pt[tree[x].l]&&pt[tree[x].r+1]<=r)
    {
        tree[x].sum+=c;
        update(x);
        return ;
    }
//    int mid=tree[x].l+tree[x].r>>1;
    change(x<<1,l,r,c);
    change(x<<1|1,l,r,c);
    update(x);
}
signed main()
{
    int n;cin>>n;
    for(int i=1;i<=n;i++)
    {
        int r1,h1,h2,r2;cin >> r1 >> h1 >> r2 >> h2;
        arr[i*2-1]={r1, r2, h1, 1};
        arr[i*2]  ={r1, r2, h2, -1};
        pt[i * 2 - 1]=r1;pt[i * 2]=r2;
    }
    n<<=1;
    sort(pt + 1, pt + 1 + n);
    int tot= unique(pt + 1, pt + 1 + n) - pt - 1;
    build(1,1,tot-1);
    int res=0;
    for(int i=1;i<n;i++)
    {
        change(1, arr[i].l, arr[i].r, arr[i].mark);
        res+=(arr[i+1].h-arr[i].h)*tree[1].len;
        cout<<tree[1].len<<" ";
    }
    cout<<res;
}
2025/7/25 11:06
加载中...