SKYLINE
题意:给出l r h如果h大于原来l r区间里的hi那么将覆盖掉 l r里面的hi求覆盖的区间长度。
思路:区间更新,查询区间最值的线段数维护即可。
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
int ql,qr,n,mmax[maxn],_set[maxn],ans,h;
void init(){
ans=0;
for(int i=0;i<maxn;i++)
mmax[i]=_set[i]=0;
}
void pushdown(int o,int l,int r){
if(_set[o]){
_set[o]=0;
_set[l]=_set[r]=1;
mmax[l]=mmax[r]=mmax[o];
}
}
void up(int o,int l,int r){
if(ql<=l&&qr>=r&&mmax[o]<=h){
_set[o]=1;
mmax[o]=h;
ans+=r-l+1;
return;
}
if(mmax[o]>h&&_set[o]==1)
return;
int ls=o*2,rs=o*2+1;
pushdown(o,ls,rs);
int m=(l+r)>>1;
if(ql<=m)
up(o*2,l,m);
if(qr>m)
up(o*2+1,m+1,r);
mmax[o]=max(mmax[o*2],mmax[o*2+1]);
}
int main(){
ios::sync_with_stdio(false);
int T;
while(cin>>T&&T){
while(T--){
cin>>n;
init();
while(n--){
cin>>ql>>qr>>h;
qr--;
up(1,1,100000);
}
cout<<ans<<"\n";
}
}
}