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&&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