#include <iostream> #include <cstdio> #include <cstring> #include <string> #include < algorithm>using namespace std; #define MAXN 1000000 + 10#define Lson L, Mid, Root<<1#define Rson mid+1, R, root< ; <1|1#define INF 0x7ffffffint min[maxn<<2], a[maxn];int num;void pushup (int root) {Min[root] = Min (Min[root< ; <1], min[root<<1|1]);} void Bulid (int L, int R, int root) {if (L = = R) {Min[root] = A[++num]; return; } int mid = (L + R) >> 1; Bulid (Lson); Bulid (Rson); Pushup (root);} void Update (int q, int val, int L, int R, int root) {if (L = = R) {Min[root] = val; return; } int mid = (L + R) >> 1; if (q <= mid) Update (Q, Val, Lson); else Update (Q, Val, Rson); Pushup (root);} int Query (int l, int r, int l, int r, int root) {if (l<=l && r>=r) {return min[root]; } int res = INF; int mid = (L + R) >> 1; if (L <= mid) Res = Min (res, Query (l, R, Lson)); if (R > Mid) res = min (res, Query (l, R, Rson)); return res;} int main () {int n, q; while (~SCANF ("%d", &n)) {for (int i=1; i<=n; i++) scanf ("%d", &a[i]); num = 0; Bulid (1, N, 1); scanf ("%d", &q); int K1, K2, K3; while (q--) {scanf ("%d%d%d", &k1, &k2, &K3); if (K1) Update (K2, K3, 1, N, 1); else printf ("%d\n", Query (K2, K3, 1, N, 1)); }} return 0;}
Line Tree water problem #1077: RMQ problem-line tree