First, the coordinates are discretization, and then the line segment tree area is updated.
When updating, you should first update the short ones and then make the high ones overwrite the short ones.
The time complexity is O (n * log (n ))
Note long
Note that the length of a line segment tree must be maxn x 2x4.
#include
#include#include
#include
#include
#include
#define INF 1000000#define LL long long#define maxn 80200using namespace std;struct list{ int l; int r; int h;}node[maxn*4+10];struct lose{ int x; int y; int h; bool friend operator < (const lose a, const lose b) { return a.h
x)r=mid; if(xx[mid]
mid )insert(l,r,h,num*2+2); else if(r<=mid)insert(l,r,h,num*2+1); else { insert(l,mid,h,num*2+1); insert(mid+1,r,h,num*2+2); }}int search(int x,int num){ int a=node[num].l; int b=node[num].r; int mid=(a+b)/2; if(node[num].h!=0)return node[num].h; if(a==b) { return 0; } if(x<=mid)return search(x,num*2+1); else return search(x,num*2+2);}int main(){ int n; while(~scanf("%d",&n)) { for(int i=0;i