We need to write a program that manipulates a sequence A of n elements, initially all equal to 2^31-1 = 2147483647. There are two operations: update(i, x) set a[i] = x, and find(s, t) return min in range [s, t]. There are up to 100000 updates and queries, n up to 100000. So we need efficient range minimum queries with point updates. This is classic segment tree (or Fenwick tree for min? Fenwick can handle prefix min but not arbitrary range min easily, but we can use segment tree). Alternatively use a binary indexed tree with min? Usually BIT is for sum; for min we can use segment tree.
Thus solution: build segment tree of size n with initial value INF. Support point update (set value) and range minimum query. Complexity O((n+q) log n).
Input: first line n q. Then q lines each with com x y. com=0: update(x, y) (set a[x] = y). com=1: find(x, y) (query min from x to y inclusive). Output result for each find.
Edge cases: s and t? The problem says: find(s, t): report minimum in as,..., at. So inclusive. In example, they query 0 2 and 1 2. So inclusive.
Note: xi, yi correspond to parameters. For update: i = xi, x = yi. For find: s = xi, t = yi.
Constraints: 0 <= xi < n, yi can be up to 2^31-1 for update, and for find yi < n. So we handle accordingly.
Implementation details: Since initial values are INF (2147483647), for a find on an un-updated segment, the min will be INF. In example 2: first query find(0,0) on initial array gives 2147483647.
Segment tree: We can store tree as array of size 4*n. Build: set all leaf to INF. Or we can lazy build? Not needed as we can start with INF and update values as we go. For query we need to handle range inclusive.
We'll parse input with sys.stdin.
Potential pitfalls: The update operation sets a[i] to x, not adds. So we can do point assignment. In segment tree, for assignment we update leaf and propagate up with min of children.
Also note: The range minimum query returns minimum; if the segment has not been updated, the INF will be present, but that's fine.
Complexities: O((n+q) log n) fits.
We can implement segment tree class.
Let's write the code.
Pseudo:
import sys
def main():
import sys
input = sys.stdin.readline
n, q = map(int, input().split())
INF = 2147483647
size = 1
while size < n:
size <<= 1
seg = [INF] * (2 * size) # for 1-indexed? We'll use 0-indexed segment tree with size as power of two.
# But we need to handle n not power of two: typical segment tree with leaves at offset size.
# Actually we can implement recursive? For performance, iterative segment tree may be faster.
# But Python recursion might be okay for 210^5 operations? Possibly iterative segment tree is simpler.
# I'll implement iterative segment tree (size = next power of 2). Leaves are seg[size + i] for i in range(n).
# For query on [l, r] inclusive, we do l += size, r += size, res = INF, while l <= r: if l%2==1: res = min(res, seg[l]); l+=1; if r%2==0: res = min(res, seg[r]); r-=1; l//=2; r//=2.
# For update: i += size; seg[i] = x; then i//=2 while i>=1: seg[i] = min(seg[2i], seg[2i+1]).
# This works as long as we set unused leaves to INF.
# So we need seg array of length 2size, with indices from 1 to 2size-1 if we use 1-indexed? Actually using 0-indexed leaves at offset size: we can store from 0 to 2size-1. But then children indices: for node at index i, left child = 2i, right = 2i+1 if we use 0-index? That becomes messy. Usually iterative segtree uses 1-indexed base: size is power of two, seg = [INF](2size). Leaves at indices size to size+n-1. Then for index i (0-based), leaf = size + i. Then while i>1: i//=2, update. For query, we use l = size+l, r = size+r, and while l<=r: ... using 1-indexed? Actually if we use 1-indexed, l and r are indices in the seg array. We need to start with l += size, r += size. But if size is 1-indexed, we need to adjust: we want leaves at [size, size+n-1]. So we can set seg = [INF](2size) and ignore index 0. Then leaf index = size + i. Then l = leaf_left, r = leaf_right. Then while l <= r: if l % 2 == 1: ...; if r % 2 == 0: ...; then l//=2; r//=2. This works because l and r are indices in 1-indexed array (starting at 1). So we need to make sure seg array length is 2size, and we use indices from 1 to 2size-1. So we allocate seg = [INF] * (2*size). We'll ignore seg[0]. For leaves: for i in range(n): seg[size + i] = INF (already set). For the rest of leaves beyond n, they remain INF which is fine.
# Alternatively, we can use recursive segment tree, simpler code:
# Build function recursively sets. But maybe iterative is faster.
# We'll go with iterative.
size = 1
while size < n:
size <<= 1
seg = [INF] * (2 * size) # index 0 unused
def update(pos, value):
i = size + pos
seg[i] = value
i //= 2
while i:
seg[i] = min(seg[2*i], seg[2*i+1])
i //= 2
def query(l, r):
# inclusive
l += size
r += size
res = INF
while l <= r:
if l % 2 == 1:
res = min(res, seg[l])
l += 1
if r % 2 == 0:
res = min(res, seg[r])
r -= 1
l //= 2
r //= 2
return res
out_lines = []
for _ in range(q):
line = input().split()
if not line:
continue
com, x, y = map(int, line)
if com == 0:
update(x, y)
else: # com == 1
res = query(x, y)
out_lines.append(str(res))
sys.stdout.write("\n".join(out_lines))
if name == "main":
main()
Test with given examples:
Example 1:
n=3 q=5
updates: (0,1),(1,2),(2,3)
find 0 2 -> min(1,2,3)=1
find 1 2 -> min(2,3)=2
Outputs: 1 and 2.
Our code: initial seg all INF. After updates, correct. Works.
Example 2:
n=1 q=3
find 0 0 -> INF
update 0 5
find 0 0 -> 5
Output: 2147483647 and 5. Works.
Edge Cases: s>t? According to problem, find(s,t) presumably s <= t. But not explicitly? It says find(s, t) report minimum in as,...,at. Typically s <= t. But we can handle if s>t: we can swap? The constraints might guarantee? I'll assume s <= t (since they say s, t and example uses s <= t). But for safety, we can handle: if s>t: swap? Probably not needed.
Also note: For updates, x is index, y is value. y can be up to 2^31-1, which is INF. So values can be equal to INF. That's fine.
Time complexity: O(q log n) ~ 100000*17 = 1.7M operations, fine.
Memory: seg size up to 2*131072=262144 (if n=100000, next pow2 is 131072) which is fine.
Potential issue: Python recursion limit not used.
I'll add a fast I/O.
One more thing: The initial values are 2^31-1, which is 2147483647. That's the maximum 32-bit signed integer, but also INF. Use that.
Thus final answer: Provide the code with explanation.
But the user asked: "Write a program which manipulates..." So we need to output the code.
We'll produce a complete Python solution.
We should also consider using sys.setrecursionlimit if we used recursion, but we aren't.
Now I'll produce final answer. ```python
import sys
def main() -> None:
input = sys.stdin.readline
n, q = map(int, input().split())
INF = 2147483647
# build iterative segment tree (size = next power of two)
size = 1
while size < n:
size <<= 1
seg = [INF] * (2 * size) # 1‑based, index 0 unused
def update(pos: int, value: int) -> None:
"""set A[pos] = value"""
i = size + pos
seg[i] = value
i //= 2
while i:
seg[i] = min(seg[2 * i], seg[2 * i + 1])
i //= 2
def query(left: int, right: int) -> int:
"""return min A[left .. right] (inclusive)"""
l = size + left
r = size + right
res = INF
while l <= r:
if l % 2 == 1:
res = min(res, seg[l])
l += 1
if r % 2 == 0:
res = min(res, seg[r])
r -= 1
l //= 2
r //= 2
return res
out = []
for _ in range(q):
com, x, y = map(int, input().split())
if com == 0:
update(x, y)
else: # com == 1
out.append(str(query(x, y)))
sys.stdout.write("\n".join(out))
if name == "main":
main()