POJ 3264-balanced LINEUP-RMQ Problems

Source: Internet
Author: User

Bare RMQ Problem

1#include <cstdio>2#include <algorithm>3#include <cstring>4 5 using namespacestd;6 7 Const intMAXN =50010;8 9 intmin_dp[maxn][ -],max_dp[maxn][ -];Ten intMIN_MM[MAXN],MAX_MM[MAXN]; One intB[MAXN]; A intn,q; -  - voidMIN_INITRMQ (intNintb[]) the { -min_mm[0] = -1; -          for(intI=1; i<=n;i++) -         { +Min_mm[i] = ((i& (i-1)) ==0) ? min_mm[i-1]+1: min_mm[i-1]; -min_dp[i][0] =B[i]; +         } A          for(intj=1; j<=min_mm[n];j++) at                  for(intI=1; i + (1&LT;&LT;J)-1<= n;i++) -Min_dp[i][j] = min (min_dp[i][j-1],min_dp[i+ (1<< (J-1))][j-1]); -  - } -  - intMIN_RMQ (intXinty) in { -         intK = min_mm[y-x+1]; to         returnMin (min_dp[x][k],min_dp[y-(1&LT;&LT;K) +1][k]); + } -  the  * voidMAX_INITRMQ (intNintb[]) $ {Panax Notoginsengmax_mm[0] = -1; -          for(intI=1; i<=n;i++) the         { +Max_mm[i] = ((i& (i-1)) ==0) ? max_mm[i-1]+1: max_mm[i-1]; Amax_dp[i][0] =B[i]; the         } +          for(intj=1; j<=max_mm[n];j++) -                  for(intI=1; i + (1&LT;&LT;J)-1<= n;i++) $MAX_DP[I][J] = max (max_dp[i][j-1],max_dp[i+ (1<< (J-1))][j-1]); $  - } -  the intMAX_RMQ (intXinty) - {Wuyi         intK = max_mm[y-x+1]; the         returnMax (max_dp[x][k],max_dp[y-(1&LT;&LT;K) +1][k]); - } Wu  - intMain () About { $         //freopen ("input.in", "R", stdin); -          while(~SCANF ("%d%d",&n,&Q)) -         { -                  for(intI=1; i<=n;i++) A                 { +scanf"%d",&b[i]); the                 } - MIN_INITRMQ (n,b); $ MAX_INITRMQ (n,b); the  the                  for(intI=0, l,r;i<q;i++) the                 { thescanf"%d%d",&l,&R); -printf"%d\n", MAX_RMQ (L,R)-MIN_RMQ (l,r)); in                         //printf ("%d\n", MAX_RMQ (L,r)); the                 } the         } About}

POJ 3264-balanced LINEUP-RMQ Problems

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.