标签:
1 #include<stdio.h> 2 int n, m; 3 int a[10]; 4 int tree[6<<2]; 5 6 int minx(int a, int b) 7 { 8 return a<b?a:b; 9 } 10 11 void build(int rt, int l, int r) 12 { 13 if(l==r) 14 { 15 tree[rt]=a[l]; 16 } 17 else 18 { 19 int m=(l+r)>>1; 20 build(rt<<1, l, m); 21 build((rt<<1)+1, m+1, r); 22 23 tree[rt]=minx(tree[rt<<1], tree[(rt<<1)+1]); 24 } 25 } 26 27 int query(int rt, int l, int r, int a, int b) 28 { 29 if(a<=l && b>=r) 30 return tree[rt]; 31 if(a>r || b<l) 32 return -1; 33 int m=(l+r)>>1; 34 int x=query(rt<<1, l, m, a, b); 35 int y=query((rt<<1)+1, m+1, r, a, b); 36 if(x==-1) 37 return y; 38 if(y==-1) 39 return x; 40 if(x<=y) 41 return x; 42 return y; 43 } 44 45 void updata(int rt, int l, int r, int a, int b) 46 { 47 if(l==r) 48 { 49 tree[rt]=b; 50 } 51 else 52 { 53 int m=(l+r)>>1; 54 if(a<=m) 55 updata(rt<<1, l, m, a, b); 56 else 57 updata((rt<<1)+1, m+1, r, a, b); 58 tree[rt]=minx(tree[rt<<1], tree[(rt<<1)+1]); 59 } 60 } 61 62 int main() 63 { 64 while(scanf("%d%d", &n, &m)==2) 65 { 66 for(int i=1; i<=n; i++) 67 scanf("%d", &a[i]); 68 build(1, 1, n); 69 70 for(int j=0; j<m; j++) 71 { 72 char x; 73 int a, b; 74 getchar(); 75 scanf("%c%d%d", &x, &a, &b); 76 if(x==‘Q‘) 77 printf("%d\n", query(1, 1, n, a, b)); 78 else 79 updata(1, 1, n, a, b); 80 } 81 } 82 return 0; 83 }
http://blog.csdn.net/metalseed/article/details/8039326#
借来
标签:
原文地址:http://www.cnblogs.com/qyy-goodluck/p/4352962.html