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++14 (judge verdict: Accepted)

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

template<class Monoid>
class SegmentTree{
private:
  using T = typename Monoid::T;
  const size_t n;
  vector<T> d;

  void build(){
    for(size_t b = n - 1; b > 0; b--) d[b] = Monoid::op(d[b << 1], d[b << 1 | 1]);
  }

public:
  SegmentTree(size_t n)
    : n(n), d(2 * n, Monoid::identify()) {}

  template<typename InputItr>
  SegmentTree(InputItr first, InputItr last)
    : n(distance(first - last)), d(2 * n, Monoid::identify()){
    copy(first, last, next(d.begin(), n));
    build();
  }

  void modify(size_t k, T v){
    for(d[k += n] = v; k > 1; k >>= 1) d[k >> 1] = Monoid::op(d[k], d[k ^ 1]);
  }

  T query(T l, T r){
    T res {Monoid::identify()};
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l&1) res = Monoid::op(res, d[l++]);
      if (r&1) res = Monoid::op(res, d[--r]);
    }
    return res;
  }

  void dump(){
    FOR(i, n, 2 * n) cout << i - n << ": " << d[i] << endl;
  }
};

template<typename U = ll>
struct RSQ{
  using T = U;
  static T op(const T& a, const T& b){ return a + b; };
  static constexpr T identify(){ return T(0); };
};

template<typename U = ll>
struct RMQ{
  using T = U;
  static T op(const T& a, const T& b){ return min<T>(a, b); };
  static constexpr T identify(){ return numeric_limits<T>::max(); };
};

int main() {
  int n, q; cin >> n >> q;
  SegmentTree<RMQ<int>> tree(n);

  while(q--){
    int c, x, y;
    cin >> c >> x >> y;

    switch(c){
      case 0:
        tree.modify(x, y);
        break;
      case 1:
        cout << tree.query(x, y+1) << endl;
        break;
    }

  }
  return 0;
}