Skip to content

Instantly share code, notes, and snippets.

@sofhiasouza
Created August 20, 2019 15:00
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 sofhiasouza/5bb58dfe86ba0a40a5ceeff9a8322716 to your computer and use it in GitHub Desktop.
Save sofhiasouza/5bb58dfe86ba0a40a5ceeff9a8322716 to your computer and use it in GitHub Desktop.
int st[4*maxn]; //minha segtree de frequencia
int busca_seg(int p, int l, int r, int k)
{
if(l == r) return l; //se l e r são iguais, cheguei no valor que eu queria
int meio = (l+r)/2;
if(st[p*2] >= k) //se meu filho da esquerda tiver pelo menos k valores, o k-esimo esta nele
{
return busca_seg(p*2, l, meio, k);
}
else //senao, o k-esimo esta no meu filho da direita
{
return busca_seg(p*2+1, meio+1, r, k-st[p*2]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment