题意:区间查询、单点修改
source:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
solution:简单的线段树、看一下之前的几篇线段树就会了、这里不再赘述
#include <bits/stdc++.h>
using namespace std;
#define Mid ((l+r)>>1)
#define lson rt<<1,l,Mid
#define rson rt<<1|1,Mid+1,r
const int maxn= 100000+5;
int arr[maxn<<2];
void build(int rt,int l,int r){
if(l==r)arr[rt] = 2147483647;
else{
build(lson);
build(rson);
arr[rt] = min(arr[rt<<1], arr[rt<<1|1]);
}
}
void updata(int rt,int l,int r,int pos,int num){
if(l == r && r == pos)
arr[rt] = num;
else{
if( pos <= Mid)
updata(lson,pos,num);
else
updata(rson,pos,num);
arr[rt] = min(arr[rt<<1], arr[rt<<1|1]);
}
}
int query(int rt,int l,int r,int L,int R){
if(L <= l && r <= R)
return arr[rt];
else{
int tmp = 2147483647;
if( L <= Mid)
tmp = min(query(lson,L,R), tmp);
if( R > Mid)
tmp = min(query(rson,L,R), tmp);
return tmp;
}
}
int main(){
int n, q, ch, x, y;
scanf("%d %d", &n, &q);
build(1,1,n);
while (q--){
scanf("%d%d%d", &ch, &x, &y);
if (ch)printf("%d\n", query(1, 1, n, x + 1, y + 1));
else updata(1, 1, n, x + 1, y);
}
return 0;
}