Created
August 20, 2019 15:00
-
-
Save sofhiasouza/5bb58dfe86ba0a40a5ceeff9a8322716 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
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