HDU 1754 block chain Form point modification + single point query

Source: Internet
Author: User

Classic line tree Topics can also be done with a block list.

1#include <iostream>2#include <cstring>3#include <cstdio>4#include <cmath>5 using namespacestd;6 7 Const intN =200000;8 Const intM = -;9 intN, m, tot;Ten  One intMaxintAintb) A { -     returna > B?a:b; - } the  - structBlock - { -     intNum[m]; +     intsize, MAXN; -     voidInit () +     { ASize = MAXN =0; at     } -     voidPushinttmp) -     { -num[size++] =tmp; -         if(tmp > MAXN) MAXN =tmp; -     } in } Bl[m]; -  to voidUpdateintPosintv) + { -     intCur =0; the      while(Pos >bl[cur].size) *     { $pos-=bl[cur].size;Panax Notoginsengcur++; -     } theBl[cur].num[pos-1] =v; +BL[CUR].MAXN =0; A      for(inti =0; i < bl[cur].size; i++ ) the     { +BL[CUR].MAXN =Max (BL[CUR].MAXN, Bl[cur].num[i]); -     } $ } $  - intQueryintLintR) - { the     intCur =0, Inc = R-l; -      while(L >bl[cur].size)Wuyi     { theL-=bl[cur].size; -cur++; Wu     } -     intNcur =cur; AboutR = L +Inc; $      while(R >bl[ncur].size) -     { -R-=bl[ncur].size; -ncur++; A     } +     intAns =0; the      for(inti = cur +1; I <= ncur-1; i++ ) -     { $Ans =Max (ans, bl[i].maxn); the     } the     if(cur = =ncur) the     { the          for(intj = L-1; J < R; J + + ) -         { inAns =Max (ans, bl[cur].num[j]); the         } the     } About     Else the     { the          for(intj = L-1; J < Bl[cur].size; J + + ) the         { +Ans =Max (ans, bl[cur].num[j]); -         } the          for(intj =0; J < R; J + + )Bayi         { theAns =Max (ans, bl[ncur].num[j]); the         } -     } -     returnans; the } the  the intMain () the { -      while(SCANF ("%d%d", &n, &m)! =EOF) the     { thetot =0; the bl[tot].init ();94         intPS = sqrt ((Double) n); the          for(inti =0; I < n; i++ ) the         { the             inttmp;98scanf"%d", &tmp); About             if(Bl[tot].size = =PS) -             {101tot++;102 bl[tot].init ();103             }104 Bl[tot].push (TMP); the         }106         Charop[2];107         intA, B;108          while(m-- )109         { thescanf"%s%d%d", OP, &a, &b);111             if(op[0] =='Q' ) the             {113printf"%d\n", query (A, b)); the             } the             Else the             {117 Update (A, b);118             }119         } -     }121     return 0;122}

HDU 1754 block chain Form point modification + single point query

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.