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