Skip to content

Commit dbbdbc2

Browse files
lrvideckisadamant-pwn
authored andcommitted
simplify initiation
1 parent d865519 commit dbbdbc2

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/data_structures/sparse-table.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ int st[K + 1][MAXN];
4242
Because the range $[i, i + 2^j - 1]$ of length $2^j$ splits nicely into the ranges $[i, i + 2^{j - 1} - 1]$ and $[i + 2^{j - 1}, i + 2^j - 1]$, both of length $2^{j - 1}$, we can generate the table efficiently using dynamic programming:
4343

4444
```{.cpp file=sparsetable_generation}
45-
for (int i = 0; i < N; i++)
46-
st[0][i] = f(array[i]);
45+
st[0] = array;
4746

4847
for (int j = 1; j <= K; j++)
4948
for (int i = 0; i + (1 << j) <= N; i++)
@@ -64,8 +63,7 @@ We can construct the data structure with:
6463
```{.cpp file=sparsetable_sum_generation}
6564
long long st[K + 1][MAXN];
6665

67-
for (int i = 0; i < N; i++)
68-
st[0][i] = array[i];
66+
st[0] = array;
6967

7068
for (int j = 1; j <= K; j++)
7169
for (int i = 0; i + (1 << j) <= N; i++)
@@ -127,8 +125,7 @@ Afterwards we need to precompute the Sparse Table structure. This time we define
127125
```{.cpp file=sparse_table_minimum_generation}
128126
int st[K + 1][MAXN];
129127
130-
for (int i = 0; i < N; i++)
131-
st[0][i] = array[i];
128+
st[0] = array;
132129
133130
for (int j = 1; j <= K; j++)
134131
for (int i = 0; i + (1 << j) <= N; i++)

0 commit comments

Comments
 (0)