# hdu2795 Billboard Segment Tree

Source: Internet
Author: User

Test instructions

Give a h*w billboard, there are n 1*u posters, posters as far as possible, to the left of the position posted, ask each poster can be affixed to how high.

Segment Tree single point modification.

Note: since 1 <= h,w <= 10^9; 1 <= N <= 200,000, but in fact, if h>n, the worst case is just the first n rows.

So if H>n is H=n

If you do not add this sentence, because the line segment tree array to open to h<<2 so large, and h<= 10^9, so the input h too large will make the open array too large. If you add it, you won't, n<<2 is OK.

`1#include <cstdio>2#include <algorithm>3 using namespacestd;4 #defineLson l,m,rt<<15 #defineRson m+1,r,rt<<1|16 Const intMaxh=200010;7 int_max[maxh<<2];8 intans;9 voidPushup (intRT)Ten { One_max[rt]=max (_max[rt<<1],_max[rt<<1|1]); A } - voidQueryintUintLintRintRT) - { the     if(l==R) { -_max[rt]-=u; -ans=l; -         return ; +     } -     intM= (l+r) >>1; +     if(_max[rt<<1]>=u) A query (U,lson); at     Else - query (U,rson); - pushup (RT); - } - intMain () - { in     intH,w,n; -      while(SCANF ("%d%d%d", &h,&w,&n)! =EOF) { to         if(h>N) +H=N; -          for(intI=1; I<= (h<<2); i++) the_max[i]=W; *         intu; \$          for(intI=0; i<n;i++){Panax Notoginsengscanf"%d",&u); -             if(_max[1]<u) theprintf"-1\n"); +             Else{ AQuery (U,1H1); theprintf"%d\n", ans); +             } -         } \$     } \$     return 0; -}`
View Code

hdu2795 Billboard Segment Tree

Related Keywords:

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.