MCPcopy Create free account
hub / github.com/ShahjalalShohag/code-library / build

Function build

Data Structures/Sparse Table 2D.cpp:19–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19void build(int n, int m) { // 0 indexed
20 for (int i = 2; i < N; i++) lg2[i] = lg2[i >> 1] + 1;
21 for (int i = 0; i < n; i++) {
22 for (int j = 0; j < m; j++) {
23 st[i][j][0][0] = a[i][j];
24 }
25 }
26 for (int a = 0; a < LG; a++) {
27 for (int b = 0; b < LG; b++) {
28 if (a + b == 0) continue;
29 for (int i = 0; i + (1 << a) <= n; i++) {
30 for (int j = 0; j + (1 << b) <= m; j++) {
31 if (!a) {
32 st[i][j][a][b] = max(st[i][j][a][b - 1], st[i][j + (1 << (b - 1))][a][b - 1]);
33 } else {
34 st[i][j][a][b] = max(st[i][j][a - 1][b], st[i + (1 << (a - 1))][j][a - 1][b]);
35 }
36 }
37 }
38 }
39 }
40}
41
42string s[N];
43int l[N][N], u[N][N];

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected