Poj-3277-City Horizon-discretization + line segment tree region update

Source: Internet
Author: User

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
        
         

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.