Line tree build, query, single point update

Source: Internet
Author: User

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

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.