-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11235.cpp
66 lines (52 loc) · 1.06 KB
/
11235.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
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
struct SegmentTree
{
vector<int> ST;
int N;
SegmentTree(vector<int> &A){
N = A.size();
ST.resize(4 * N);
build(1, 0, N - 1, A);
}
void build(int n, int l, int r, vector<int> &A){
if (l == r){
ST[n] = A[r];
return;
}
build(2 * n, l, (l + r) / 2, A);
build(2 * n + 1, (l + r) / 2 + 1, r, A);
ST[n] = min(ST[2 * n], ST[2 * n + 1]);
}
int query(int i, int j)
{
return query(1, 0, N - 1, i, j);
}
int query(int n, int l, int r, int i, int j){
if (r < i || j < l)
return inf;
if (i <= l && r <= j)
return ST[n];
return min(query(2 * n, l, (l + r) / 2, i, j),
query(2 * n + 1, (l + r) / 2 + 1, r, i, j));
}
};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
while(cin >> n && n != 0){
vector<int> vec(n), freq(n);
cin >> m;
for(int i=0; i<n; i++){
cin >> vec[i];
}
SegmentTree ST(vec);
while(m--){
int i, j;
cin >> i >> j;
}
}
return 0;
}