aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDushyant Singh2021-12-12 17:22:34 +0530
committerGitHub2021-12-12 17:22:34 +0530
commit7761f38957fecd5f45bc62d55e9a77636a2b11d5 (patch)
tree26b77806987c2cc2e4f1e0e4e22a58d88a2593b5
parent924653b7cd41d61bbe973434f0b972f3d5e8f75f (diff)
fix off by one in sparse table
Given code fails for `query(0, n - 1)` Problem to test on https://codeforces.com/contest/1549/problem/D
-rw-r--r--Data Structures/sparse_table.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/Data Structures/sparse_table.cpp b/Data Structures/sparse_table.cpp
index c303930..841674e 100644
--- a/Data Structures/sparse_table.cpp
+++ b/Data Structures/sparse_table.cpp
@@ -8,7 +8,7 @@ public:
for (int i = 0; i <= log(N); i++) st[i].resize(N);
for (int i = 0; i < N; i++) st[0][i] = A[i];
for (int i = 1; i <= log(N); i++) {
- for (int j = 0; j + (1 << i) < N; j++) st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
+ for (int j = 0; j + (1 << i) <= N; j++) st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
}
}