#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 0x7ffffff int 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; }
时间: 2024-10-11 13:40:09