[LA-4108] Skyline 线段树/树状数组+二分 发表于 2018-02-22 | 分类于 线段树 字数统计: 336字 | 阅读时长 ≈ 2分钟 题面传送门: LA-4108 样例Sample Input135 11 31 10 13 13 20Sample Output14 思路线段树区间更新维护最大值即可 裸题啊 代码1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include<bits/stdc++.h>using namespace std;#define lc rt<<1#define rc rt<<1|1#define maxn 100010inline void read(int &x){ x=0;char ch=getchar();int f=1; while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();} x*=f;}int ans = 0,n;struct SegmentTree{ int lazy[maxn<<2],maxv[maxn<<2]; void Pushup(int rt) { maxv[rt] = max(maxv[lc],maxv[rc]); } void Pushdown(int rt) { lazy[lc] = max(lazy[lc],lazy[rt]); lazy[rc] = max(lazy[rc],lazy[rt]); } void Update(int rt,int l,int r,int x,int y,int v) { if (lazy[rt] > v) return ; if (x <= l && y >= r && v >= maxv[rt]) { ans += (r-l+1); maxv[rt] = v; lazy[rt] = v; return ; } if (l == r) return ; Pushdown(rt); int m = (l+r) >> 1; if (x <= m) Update(lc,l,m,x,y,v); if (y > m) Update(rc,m+1,r,x,y,v); Pushup(rt); }}Tree;int main(int argc, char *argv[]){ int t,f,g,h; read(t); { while(t--) { ans = 0; memset(Tree.lazy,0,sizeof(Tree.lazy)); memset(Tree.maxv,0,sizeof(Tree.maxv)); read(n); while(n--) { read(f),read(g),read(h); Tree.Update(1,1,maxn,f,g-1,h); } printf("%d\n",ans); } } return 0;}