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 <vector> 
#include <list> 
#include <map>
#include <set>//2分探索木
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>// キュー　優先度付きキュー
#include <stack>
#include <complex>
#include <memory>
#include <assert.h>
#ifdef LOCAL
#include "UnionFind.h"//同じグループに属するか
#include "Prime.h"//素数判定
#include "RMQ.h"//区間最小値
#include "BIT.h"//累積和
#endif

using namespace std;

//conversion
//------------------------------------------
inline long long toInt(string s) { long long v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<PII> VPII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(t,c) for(typeof((c).begin()) t=(c).begin(); t!=(c).end(); ++t)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(t,a,b) for(int t=(a);t<(b);++t)
#define REP(t,n)  FOR(t,0,n)

//constant
//------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
//------------------------------------------
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
//------------------------------------------
#if defined(__GNUC__) 
#include <assert.h>
#define ASSERT_(x) assert(x)
#else
#include <assert.h>
#define ASSERT_(x) assert(x)
#endif
#ifdef _DEBUG
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;
#define ASSERT(x) {if (!(x)){std::cerr << "\nError!!\n" << "info string file:" << __FILE__ << " line:" << __LINE__ <<" "<< #x<< std::endl;ASSERT_(x);}}
#else
#define ASSERT(x) ((void)0)
#define debug(x) ((void)0)
#define dump(x)  ((void)0)
#endif // _DEBUG
template<class T> void showVector(vector<T>& v) {
	for (int i = 0; i < v.size(); ++i)
		cerr << v[i] << " ";
	cerr << endl;
}


//mod
//-------------------------------------------
const LL mod = 1000000007;
LL mod_pow(LL x, LL n, LL mod) {
	if (n == 0) { return 1; }
	LL res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) { res = res * x % mod; }
	return res;
}

//bitop
//-------------------------------------------
#if defined(__GNUC__)
#include <immintrin.h>
int popcount(int a) {
	return __builtin_popcount(a);
}
#elif defined(_MSC_VER)
#include <intrin.h>
int popcount(int a) {
	return __popcnt(a);
}
#endif 

//gcd lcm
//-------------------------------------------
LL gcd(LL a, LL b) { if (a%b == 0) { return b; } else return gcd(b, a%b); }
LL lcm(LL a, LL b) { return a / gcd(a, b)*b; }


//YES_NO
//------------------------------------------
#define Yes_ cout<<"Yes"<<endl; return 0;
#define No_ cout<<"No"<<endl; return 0;

#define YES_ cout<<"YES"<<endl; return 0;
#define NO_ cout<<"NO"<<endl; return 0;

#define POSSIBLE cout<<"POSSIBLE"<<endl; return 0;
#define IMPOSSIBLE cout<<"IMPOSSIBLE"<<endl; return 0;

//matrix
//------------------------------------------
template <class T> class matrix : public vector< vector<T> > {
private:
	int tate_, yoko_;
public:
	matrix(const int tate__, const int yoko__) {
		ASSERT(tate__ > 0); ASSERT(yoko__ > 0);
		this->resize(tate__);
		for (size_t i = 0; i < this->size(); i++) { (*this)[i].resize(yoko__); }
		tate_ = tate__; yoko_ = yoko__;
	}
	matrix() {};
	int tate()const { return tate_; }
	int yoko()const { return yoko_; }
	void resizematrix(const int tate__, const int yoko__) {
		ASSERT(tate__ > 0); ASSERT(yoko__ > 0);
		this->resize(tate__);
		for (size_t i = 0; i < this->size(); i++) {
			(*this)[i].resize(yoko__);
		}
		tate_ = tate__; yoko_ = yoko__;
	}
	void setone() {for (int i = 0; i < tate(); i++)  for (int j = 0; j < yoko(); j++) { (*this)[i][j] = 1; }}
	void setzero() {for (int i = 0; i < tate(); i++) for (int j = 0; j < yoko(); j++) { (*this)[i][j] = 0; }}
	void setAll(T a) {for (int i = 0; i < tate(); i++) for (int j = 0; j < yoko(); j++) { (*this)[i][j] = a; }}
};
template<class T> std::ostream& operator<<(std::ostream& os, const matrix<T>& m)
{
	for (int j = 0; j < m.tate(); j++) {
		for (int i = 0; i < m.yoko(); i++) {
			os << (int)m[j][i];
		}
		os << endl;
	}
	return os;
}

//time
//------------------------------------------
#if defined(__GNUC__) 
#include <sys/time.h>
#include <immintrin.h>
#include <string.h>
LL starttime;
inline LL now() {
	struct timeval tv;
	gettimeofday(&tv, NULL);
	LL t = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL;
	return t;
}
inline LL elapsed() { return now() - starttime; }
#else
#include <chrono>
#include <intrin.h>
typedef std::chrono::milliseconds::rep TimePoint;
inline TimePoint now() { return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count(); }
TimePoint starttime;
inline TimePoint elapsed() { return now() - starttime; }
#endif


//=====================================================
class RMQ {

private:
	int n;
	int dat[2 * (1 << 17) - 1];
	const int INF = 2147483647;
public:
	RMQ() {};
	RMQ(int n) { init(n); }
	void init(int N_) {

		//要素数は2のべき乗にする
		n = 1;
		while (n < N_) { n *= 2; }




		//すべての値をINTMAXで初期化
		for (int i = 0; i < 2 * n - 1; i++) {
			dat[i] = INF;
		}

	}
	//dat[k]の値をaに変更する
	//葉を変更した後、節へ遡りながら値を変更していく
	void update(int k, int a) {
		k += n - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;//indexの補正のためk-1をしてから２で割る
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);//最小値を格納する
		}
	}

	/*
	dat[a]〜dat[b]の範囲の最小値を求める

	kはこの節点のindex
	節点kはdat[l]〜dat[k]の範囲を担当している（これで通じるよね？）とする
	*/
	int query(int a, int b) {
		//return query(a, b , 0, 0, n);
		return query(a, b + 1, 0, 0, n);
	}

	int query(int a, int b, int k, int l, int r) {
		//求めたい範囲と担当範囲がかぶっていなかったのでINT_MAXを返す
		if (r <= a || b <= l) { return INF; }

		if (a <= l && r <= b) {
			return dat[k];
		}//求めたい範囲を完全に含んでいた場合はこの節点の値
		else {
			//一つ下に降りると担当範囲は1/2になる
			//２つの子の最小値を返す
			int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}


};

int main() {
	int N, Q;
	cin >> N >> Q;
	std::unique_ptr<RMQ> rl(new RMQ(N));

	REP(q, Q) {
		int a, x, y;
		cin >> a >> x >> y;
		if (a == 0) {
			rl->update(x, y);
		}
		else {
			cout <<rl->query(x,y) << endl;
		}
	}
}