hihocoder#1068 rmq-st algorithm

Source: Internet
Author: User

Original title Address

Spare Table Exercises

Remember to enter the output with scanf and printf, otherwise it will be tle

Code:

1#include <iostream>2#include <cstring>3#include <cmath>4 5 using namespacestd;6 7 #defineMax_size 10000108 9 intN, Q;Ten intW[max_size]; One intq[max_size][ +]; A  - voidbuild () { -    for(inti =1; (1<< i) <= N; i++) { the      for(intj =0; J + (1<< i) <= N; J + +) { -Q[j][i] = min (Q[j][i-1], Q[j + (1<< (I-1))][i-1]); -     } -   } + } -  + intQueryintLintr) { A   intLen = r-l +1; at   inti =0; -  -    while((1<< (i +1)) <=len) -i++; -   returnMin (Q[l][i], Q[r-(1<< i) +1][i]); - } in  - intMain () { toscanf"%d", &N); +    for(inti =0; i < N; i++) { -scanf"%d", &(W[i])); theq[i][0] =W[i]; *   } $ Panax Notoginseng build (); -  thescanf"%d", &Q); +    while(q--) { A     intL, R; thescanf"%d%d", &l, &R); +printf"%d\n", Query (L-1, R-1)); -   } $  $   return 0;

hihocoder#1068 rmq-st algorithm

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.