hihocoder1070, 1077 segment tree update point query interval

Source: Internet
Author: User

Title Link: http://hihocoder.com/problemset/problem/1070

http://hihocoder.com/problemset/problem/1077

My Code:

1#include <cstdio>2#include <algorithm>3 4 using namespacestd;5 6 #defineMAXN 10000057 8 intW[MAXN];9 Ten structSegnode One { A     intLeft , right, minw; - }; -  the structSegtree - { -Segnode t[4*MAXN]; -     voidBuildintIintLintR) +     { -T[i].left =l; +T[i].right =R; A         if(l<R) at         { -             intm = (l+r)/2; -Build2*I, L, m); -Build2*i+1, m+1, R); -t[i].minw = min (t[2*I].MINW, t[2*i+1].minw); -         } in         ElseT[I].MINW =W[l]; -     } to     intQueryintIintLintR) +     { -         if(T[I].LEFT==L&AMP;&AMP;T[I].RIGHT==R)returnt[i].minw; the         intm = (t[i].left+t[i].right)/2; *         if(l>m)returnQuery2*i+1, L, R); $         if(r<=m)returnQuery2*I, L, R);Panax Notoginseng         returnMin (Query (2*i, L, m), query (2*i+1, m+1, R)); -     } the     voidUpdateintIintIdintv) +     { A         if(t[i].left==t[i].right) T[I].MINW =v; the         Else +         { -             intm = (t[i].left+t[i].right)/2; $             if(id<=m) Update (2*I, id, v); $             ElseUpdate2*i+1, id, v); -t[i].minw = min (t[2*I].MINW, t[2*i+1].minw); -         } the     } - }tree;Wuyi  the intMain () - { Wu     intN, Q; -      while(SCANF ("%d", &n)! =EOF) About     { $          for(intI=1; i<=n; ++i) scanf ("%d", &w[i]); -Tree.build (1,1, n); -scanf"%d", &q); -          while(q--) A         { +             intop, a, B; thescanf"%d%d%d", &op, &a, &b); -             if(OP) tree.update (1, A, b); $             Elseprintf"%d\n", Tree.query (1, A, b)); the         } the     } the     return 0; the}

hihocoder1070, 1077 segment tree update point query interval

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.