1#include <stdio.h>2 intN, M;3 inta[Ten];4 inttree[6<<2];5 6 intMinxintAintb)7 {8 returnA<b?a:b;9 }Ten One voidBuildintRtintLintR) A { - if(l==R) - { thetree[rt]=A[l]; - } - Else - { + intM= (l+r) >>1; -Build (rt<<1, L, m); +Build ((rt<<1)+1, m+1, R); A atTree[rt]=minx (tree[rt<<1], tree[(rt<<1)+1]); - } - } - - intQueryintRtintLintRintAintb) - { in if(A<=l && b>=R) - returnTree[rt]; to if(A>r | | b<l) + return-1; - intM= (l+r) >>1; the intX=query (rt<<1, L, M, A, b); * intY=query ((rt<<1)+1, m+1, R, a, b); $ if(x==-1)Panax Notoginseng returny; - if(y==-1) the returnx; + if(x<=y) A returnx; the returny; + } - $ voidUpdata (intRtintLintRintAintb) $ { - if(l==R) - { thetree[rt]=b; - }Wuyi Else the { - intM= (l+r) >>1; Wu if(a<=m) -Updata (rt<<1, L, M, A, b); About Else $Updata ((rt<<1)+1, m+1, R, a, b); -Tree[rt]=minx (tree[rt<<1], tree[(rt<<1)+1]); - } - } A + intMain () the { - while(SCANF ("%d%d", &n, &m) = =2) $ { the for(intI=1; i<=n; i++) thescanf"%d", &a[i]); theBuild1,1, n); the - for(intj=0; j<m; J + +) in { the Charx; the intA, B; About GetChar (); thescanf"%c%d%d", &x, &a, &b); the if(x=='Q') theprintf"%d\n", Query (1,1, N, a, b)); + Else -Updata (1,1, N, a, b); the }Bayi } the return 0; the}
http://blog.csdn.net/metalseed/article/details/8039326#
Lend me
Line tree build, query, single point update