Created
September 21, 2015 15:09
-
-
Save tanvir002700/78a3e0b878e21e9590db to your computer and use it in GitHub Desktop.
Sparse Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Compute_ST(int N) | |
{ | |
for (int i=0;i<N;i++)ST[0][i] = i; | |
for (int k = 1;(1 << k)<N; k++) | |
{ | |
for (int i=0;i+(1<<k)<=N;i++) | |
{ | |
int x = ST[k-1][i]; | |
int y = ST[k-1][i+(1<<k-1)]; | |
ST[k][i]=A[x]<=A[y]?x:y; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment