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 <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;




struct ADD {
	int64 e;
	ADD(int64 x = 0) { e = x; }
	ADD operator*(const ADD &other) {
		return ADD(e + other.e);
	}
};
struct MIN {
	int64 e;
	MIN(int64 x = 2147483647) { e = x; }
	MIN operator~() {
		return *this;
	}
	MIN operator+(const MIN &other) {
		if (e < other.e) return *this;
		return other;
	};
	MIN operator*(const MIN &other) {
		return other;
	}
	MIN operator*(const ADD &other) {
		return MIN(e + other.e);
	}
};
struct MAX {
	int64 e;
	MAX(int64 x = std::numeric_limits<int64>::min()) { e = x; }
	MAX operator~() {
		return *this;
	}
	MAX operator+(const MAX &other) {
		if (e > other.e) return *this;
		return other;
	};
	MAX operator*(const MAX &other) {
		return other;
	}
	MAX operator*(const ADD &other) {
		return MAX(e + other.e);
	}
};
struct SUM {
	int64 e;
	int64 s;
	SUM(int64 x = 0, int64 y = 1) { e = x;s = y; }
	SUM operator~() {
		return *this;
	}
	SUM operator+(const SUM &other) {
		return  SUM(e + other.e, s + other.s);
	};
	SUM operator*(const SUM &other) {
		return SUM(s*other.e, s);
	}
	SUM operator*(const ADD &other) {
		return SUM(e + s*other.e, s);
	}
};

template<typename Monoid>
class segment_tree {
	std::vector<Monoid> tree;
	std::uint_fast32_t size;
public:
	segment_tree(std::uint_fast32_t length) {
		size = length - 1;
		size |= size >> 1;
		size |= size >> 2;
		size |= size >> 4;
		size |= size >> 8;
		size |= size >> 16;
		++size;
		tree = std::vector<Monoid>(size << 1);
		initialize();
	}
	void initialize() {
		std::uint_fast32_t i = size << 1;
		while (size < i--) { tree[i] = Monoid(); }
		++i;
		while (--i) { tree[i] = tree[i << 1] + tree[i << 1 | 1]; }
	}
	void update(std::uint_fast32_t index,std::function<Monoid(Monoid)> F) {
		index += size;
		tree[index] = F(tree[index]);
		while (index >>= 1) tree[index] = tree[index << 1] + tree[index << 1 | 1];
	}
	Monoid range(std::uint_fast32_t begin, std::uint_fast32_t end) {
		Monoid retL, retR;
		for (begin += size, end += size;begin < end;begin >>= 1, end >>= 1) {
			if (begin & 1) retL = retL + tree[begin++];
			if (end & 1)  retR = tree[end - 1] + retR;
		}
		return retL + retR;
	}
	Monoid operator[](std::uint_fast32_t index) {
		return tree[size + index];
	}
};

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n, q;
	std::cin >> n >> q;
	segment_tree<MIN> T(n);
	uint32 c, s, t;
	std::function<MIN(MIN, uint32)> F = [](const MIN &m, uint32 x)->MIN {
		return MIN((int64)x);
	};
	do {
		std::cin >> c >> s >> t;
		if (c) {
			std::cout << T.range(s, t + 1).e << "\n";
		}
		else {
			T.update(s, std::bind(F, std::placeholders::_1, t));
		}
	} while (--q);
	return 0;
}