-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSparce table.cpp
More file actions
43 lines (35 loc) · 987 Bytes
/
Sparce table.cpp
File metadata and controls
43 lines (35 loc) · 987 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
42
43
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n))
typedef bitset<10> MASK;
void fast() {
cin.tie(0);
cin.sync_with_stdio(0);
}
int main(){
fast();
}
void computeLog(int n, vector<int> &log) {
log[1]=0;
for (int i = 2; i <= n; ++i) {
log[i] = log[i / 2] + 1; //rounded down
}
}
void sparseTable(int n, vector<int> &log, vector<vector<int>> &st, vector<int> &lcp) {
for (int i = 0; i < n; i++)
st[i][0] = lcp[i];
for (int j = 1; j <= log[n]; j++)
for (int i = 0; i + (1 << j) <= n; i++)
st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
int min_range(int l, int r, vector<int> &log, vector<vector<int>> &ST) {
int len = r - l + 1;
int loge = log[len];
int sum = min(ST[l][loge], ST[r - (1 << loge) + 1][loge]);
return sum;
}