Skip to content

Instantly share code, notes, and snippets.

@Thiago4532
Created June 26, 2019 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thiago4532/7e484738361d5fe8726e82d164740003 to your computer and use it in GitHub Desktop.
Save Thiago4532/7e484738361d5fe8726e82d164740003 to your computer and use it in GitHub Desktop.
// (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