Problem:
Range Minimum Query (RMQ)

Write a program which manipulates a sequence A = {a0, a1, . . . , an-1} with the following operations:

find(s, t): report the minimum element in as, as+1, . . . ,at.

update(i, x): change ai to x.

Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1.

Input

n q
com0 x0 y0
com1 x1 y1
...
comq−1 xq−1 yq−1

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes update(xi, yi) and '1' denotes find(xi, yi).

Output

For each find operation, print the minimum element.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

If comi is 0, then 0 ≤ xi < n, 0 ≤ yi < 231-1.

If comi is 1, then 0 ≤ xi < n, 0 ≤ yi < n.

Sample Input 1

3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2

Sample Output 1

1
2

Sample Input 2

1 3
1 0 0
0 0 5
1 0 0

Sample Output 2

2147483647
5

Solution in C (judge verdict: Accepted)

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}/*swap 交換*/
ll max2(ll a,ll b){return a>=b?a:b;}/*2つのうち大きい数を返す*/ 
ll min2(ll a,ll b){return a>=b?b:a;}/*2つのうち小さい数を返す*/ 
ll ABS(ll a){return a>=0?a:(-a);}/*絶対値*/ 
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

#define MAX_N (1 << 17)
ll seg[2*MAX_N-1];
void segmake(ll n, ll a[n] ,ll t){
    rep(i,0,t) seg[t-1+i]=i<n?a[i]:INF;
    while(t/=2) rep(i,0,t) seg[t+i-1]=min2(seg[2*(t+i)],seg[2*(t+i)-1]); 
}

ll segmin(ll from, ll to, ll a, ll l, ll r){
    return (l>=from && r<=to) ? seg[a] : (l>to || r<from) ? INF : min2(segmin(from,to,2*a+1,l,(l+r)/2),segmin(from,to,2*a+2,(l+r)/2+1,r));
}

void segupdate(ll a, ll b, ll t){
    ll c=t-1+a;
    seg[c]=b;
    while(c>0){
        c--; c/=2;
        seg[c]=min2(seg[2*(c+1)],seg[2*(c+1)-1]);
    }
    // a/=2; a--;
    // if(t==2){
    //     seg[a]=min2(seg[2*(a+1)],seg[2*(a+1)-1]);
    // }
    // if(t>3){
    //     while(a>0){
    //         a--; a/=2;
    //         seg[a]=min2(seg[2*(a+1)],seg[2*(a+1)-1]);
    //         a=(a-1)/2;
    //         if(a==0){
    //             seg[a]=min2(seg[2*(a+1)],seg[2*(a+1)-1]);
    //             break;   
    //         }
    //     }
    // }
}

int main(void){
    ll n,q;
    scanf("%lld%lld",&n,&q);
    ll b[n],query[q],t=1,x[q],y[q];
    while(t<n) t*=2;
    rep(i,0,n) b[i]=2147483647;
    segmake(n,b,t);
    rep(i,0,q) scanf("%lld%lld%lld",&query[i],&x[i],&y[i]);
    rep(i,0,q){
        if(query[i]==0){
            segupdate(x[i],y[i],t);
            // rep(j,0,2*t-1) printf("%lld ",seg[j]);
            // printf("\n");
        }else{
            printf("%lld\n",segmin(x[i],y[i],0,0,t-1) );
        }
    }
    return 0;
}