-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBOJ_14438.cpp
61 lines (53 loc) · 1.39 KB
/
BOJ_14438.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000000
const ll INF = 10e12 + 10;
constexpr int SZ = 1 << 17;
using namespace std;
int N, Q, A[SZ], T[SZ << 1];
void Init(int node = 1, int s = 1, int e = N) {
if (s == e) {
T[node] = A[s];
return;
}
int m = (s + e) / 2;
Init(node * 2, s, m);
Init(node * 2 + 1, m + 1, e);
T[node] = min(T[node * 2], T[node * 2 + 1]);
}
void Update(int x, int v, int node = 1, int s = 1, int e = N) {
if (s == e) {
T[node] = v;
return;
}
int m = (s + e) / 2;
if (x <= m)Update(x, v, node * 2, s, m);
else Update(x, v, node * 2 + 1, m + 1, e);
T[node] = min(T[node * 2], T[node * 2 + 1]);
}
int Query(int l, int r, int node = 1, int s = 1, int e = N) {
if (r < s || e < l)return 1e9;
if (l <= s && e <= r) return T[node];
int m = (s + e) / 2;
return min(Query(l, r, node * 2, s, m), Query(l, r, node * 2 + 1, m + 1, e));
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> N;
for (int i = 1; i <= N; i++)
cin >> A[i];
Init();
cin >> Q;
while (Q--) {
int num, a, b;
cin >> num >> a >> b;
if (num == 1) {
Update(a, b);
} else if (num == 2) {
cout << Query(a, b) << '\n';
}
}
}