Block of interval processing

Source: Internet
Author: User

The idea of chunking is very common, which is to divide a series into k blocks and then manipulate them on the basis of blocks.

If the size of each block is magic, then the series of length n will be divided into ceil (n/magic) blocks altogether. This will have some nature:

1. The block number of the first series I is I/magic, which is the first i%magic in the block (although this one is useless).

2. If i%magic==0, stating that I is the beginning of block i/magic, the scope of section i/magic is [I/magic, (i+1)/magic).

The following is a block idea for an n-length sequence: Finds the maximum value of the sub-interval and modifies the value of a point.

1 Const intMAXN =50500;2 Const intMagic =Ten;3 intN, Q;4 intH[MAXN], B[MAXN];5 6 voidinit () {7      for(inti =0; I < n; i++) {8         if(i% Magic = =0|| H[i] > b[i/Magic]) {9B[i/magic] =H[i];Ten         } One     } A } -  - intQueryintLintr) { the     intRET =H[l]; -      for(inti = l; I <=R;) { -         if(i% Magic = =0&& i + Magic-1<=r) { -RET = max (ret, b[i/Magic]); +i + =Magic; -         } +         Else { ARET = max (ret, h[i++]); at         } -     } -     returnret; - } -  - voidUpdateintXintv) { inH[X] =v; -     intL = x/magic *Magic; to     intR = L +Magic; +      for(inti = l; I < R; i++) { -         if(i% Magic = =0|| H[i] > b[i/Magic]) { theB[i/magic] =H[i]; *         } $     }Panax Notoginseng}

Block of interval processing

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.