-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAIMI.cpp
More file actions
64 lines (57 loc) · 1.9 KB
/
Copy pathAIMI.cpp
File metadata and controls
64 lines (57 loc) · 1.9 KB
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
62
63
64
#include <fstream>
using namespace std;
ifstream cin("aimi.in");
ofstream cout("aimi.out");
const int NMAX = 100005;
const int INF = 2e9;
int n, m, t, a, b, x, arr[NMAX], segment_tree[4 * NMAX];
void Build(int node, int left, int right) {
if (left == right) {
segment_tree[node] = arr[left];
return;
}
int mid = left + (right - left) / 2;
Build(2 * node, left, mid);
Build(2 * node + 1, mid + 1, right);
segment_tree[node] = min(segment_tree[2 * node],
segment_tree[2 * node + 1]);
}
void Update(int node, int left, int right, int qleft, int qright, int delta) {
if (left > right) return;
if (qleft <= left && right <= qright) {
segment_tree[node] = delta;
cout << delta << ' ' << left << ' ' << right << '\n';
return;
}
if (qleft > right || qright < left) return;
int mid = left + (right - left) / 2;
Update(2 * node, left, mid, qleft, qright, delta);
Update(2 * node + 1, mid + 1, right, qleft, qright, delta);
segment_tree[node] = min(segment_tree[2 * node],
segment_tree[2 * node + 1]);
}
int Query(int node, int left, int right, int qleft, int qright) {
if (left > right) return INF;
if (qleft <= left && right <= qright) return segment_tree[node];
if (qleft > right || qright < left) return INF;
int mid = left + (right - left) / 2;
return min(Query(2 * node, left, mid, qleft, qright),
Query(2 * node + 1, mid + 1, right, qleft, qright));
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> arr[i];
Build(1, 1, n);
cin >> m;
while (m--) {
cin >> t >> a >> b;
if (t == 1) cout << Query(1, 1, n, a, b) << '\n';
else {
cin >> x;
Update(1, 1, n, a, b, x);
}
}
cin.close();
cout.close();
return 0;
}