HDU 1828 & amp; POJ 1177 Picture (line segment tree + scanned line + discretization)

Source: Internet
Author: User

HDU 1828 & amp; POJ 1177 Picture (line segment tree + scanning line + discretization)

HDU question address: HDU 1828 POJ question address: POJ 1177

This question is the sum of perimeter, and the method I use may be a little troublesome .. It is the line that is located in the horizontal direction first, and then the vertical line. You only need to obtain the overwrite length of each total interval, and then accumulate the absolute value of the difference between the overwrite length of this total interval and the overwrite length of the previous total interval. Because a new perimeter is generated only when the length changes.

Try scanning once again later. This blog is to be updated.

The Code is as follows:

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         #include 
          
           #include using namespace std;#define lson l, mid, rt<<1#define rson mid+1, r, rt<<1|1int sum[50000], c[50000], cnt, a[6000], b[5000], d1[6000], d2[6000], lazy[50000];struct node{ int l, r, h, f;} edge[100000];void add(int l, int r, int h, int f){ edge[cnt].l=l; edge[cnt].r=r; edge[cnt].h=h; edge[cnt++].f=f;}int cmp(node x, node y){ return x.h
           
            =r) { lazy[rt]+=x; PushUp(rt,l,r); return ; } int mid=l+r>>1; if(ll<=mid) update(ll,rr,x,lson); if(rr>mid) update(ll,rr,x,rson); PushUp(rt,l,r);}int erfen(int x, int high){ int low=0, mid; while(low<=high) { mid=low+high>>1; if(c[mid]==x) return mid; else if(c[mid]>x) high=mid-1; else low=mid+1; }}int main(){ int n, i, j, last, ans, tmp, k; while(scanf("%d",&n)!=EOF) { cnt=0; k=0; memset(sum,0,sizeof(sum)); memset(lazy,0,sizeof(lazy)); for(i=0; i
            
             

Related Article

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.