Advertisement
updown

Untitled

Jun 13th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. // find the first index in the range [ql, qr] which is >= height[ind]
  2. long long queryr2(int node, int nl, int nr, int ql, int qr, int ind) {
  3. // check if the current one is in range
  4. if (nr < ql || nl > qr)
  5. return -1;
  6.  
  7. // check if the range has a tall enough value
  8. if (seg[node] < height[ind])
  9. return -1;
  10.  
  11. // at this point, we are guaranteed the answer is in this range
  12.  
  13. if (nl == nr) {
  14. return nl;
  15. }
  16.  
  17. int mid = (nl+nr)/2;
  18.  
  19. int left_query = queryr2(node*2, nl, mid, ql, qr, ind);
  20.  
  21. if (left_query == -1)
  22. return queryr2(node*2+1, mid+1, nr, ql, qr, ind);
  23. else
  24. return left_query;
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement