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
This commit is contained in:
Dushyant Singh 2021-12-12 17:22:34 +05:30 committed by GitHub
parent 924653b7cd
commit 7761f38957
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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))]);
}
}