Http://acm.hdu.edu.cn/showproblem.php? PID = maximum value in the 2795 Interval

Source: Internet
Author: User

At the beginning, I felt that this question was a two-dimensional line segment tree. Then I analyzed it as if it was not, that is, the position of the maximum value of the interval. I felt like a part of the previous reverse order number, and the query was updated; this question is a combination of query and update. However, I won't write code for this weak dish, and then I decided to refer to the template of HH shenniu; orz... All kinds of weak and casual, just learning the line segment tree, you have to work hard in the future. For the first time so late, you are still writing code, orz .. Only me will stay up late...

Well, we will be here for a while, or else we will be suspended. I have seen a lot of news on the Internet over the past few days. I don't want this to happen to me...

Cherish life and stay away from code

#include <cstdlib>#include <iostream>#include<cstdio>#include<cmath> #include<algorithm>using namespace std;#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1 | 1const int N=200005;int num[N<<2],h,w,n;void PushUp(int rt){ num[rt]=max(num[rt<<1],num[rt<<1|1]);     } void build(int l,int r,int rt){     num[rt]=w;     if(l==r)return;      int mid=(l+r)>>1;      build(lson);      build(rson);}int Query(int val,int l,int r,int rt){  if(l==r)  {    num[rt] -= val;    return l;  }       int mid = (l+r) >> 1 ;    int res = num[rt<<1] >= val ? Query(val,lson) : Query(val,rson) ;    PushUp(rt);      return res;}int main(int argc, char *argv[]){   int val;     while(~scanf("%d%d%d",&h,&w,&n))   {     if(h>n)h=n;    build(1,h,1);     while(n--)     {       scanf("%d",&val);       if(num[1]<val)printf("-1\n");       else{            printf("%d\n",Query(val,1,h,1));            }     }   }    return EXIT_SUCCESS;}

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.