-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsparce_table.cpp
More file actions
41 lines (34 loc) · 874 Bytes
/
sparce_table.cpp
File metadata and controls
41 lines (34 loc) · 874 Bytes
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
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
struct ST{
int n;
vector <int> lg;
vector < vector <int> > sparse;
ST(vector <int> & a){
n = a.size();
lg.resize(n + 1);
lg[1] = 0;
for(int i = 2; i <= n; i++){
lg[i] = lg[i >> 1] + 1;
}
sparse.resize(n, vector <int> (lg[n] + 1));
for(int i = 0; i < n; i++){
sparse[i][0] = a[i];
}
for(int j = 1; j <= lg[n]; j++){
for(int i = 0; i <= n - (1 << j); i++){
sparse[i][j] = min(sparse[i][j - 1], sparse[i + (1 << (j - 1))][j - 1]);
}
}
}
int query(int i, int j){
int ln = lg[j - i + 1];
return min(sparse[i][ln], sparse[j - (1 << ln) + 1][ln]);
}
};
int main()
{
return 0;
}