Created
June 26, 2019 13:35
-
-
Save Thiago4532/7e484738361d5fe8726e82d164740003 to your computer and use it in GitHub Desktop.
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
// (n) é o tamanho do vetor | |
// (v) é o vetor | |
int flog(int x) { // Calcula a parte inteira do log2 de x em O(1) ( para int ) | |
return 31 - __builtin_clz(x); | |
} | |
int flog(long long x) { // Calcula a parte inteira do log2 de x em O(1) ( para long long ) | |
return 63 - __builtin_clzll(x); | |
} | |
int query(int l, int r) { | |
int k = flog(r - l + 1); | |
return min(tab[l][k], tab[r - (1<<k) + 1][k]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment