Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // find the first index in the range [ql, qr] which is >= height[ind]
- long long queryr2(int node, int nl, int nr, int ql, int qr, int ind) {
- // check if the current one is in range
- if (nr < ql || nl > qr)
- return -1;
- // check if the range has a tall enough value
- if (seg[node] < height[ind])
- return -1;
- // at this point, we are guaranteed the answer is in this range
- if (nl == nr) {
- return nl;
- }
- int mid = (nl+nr)/2;
- int left_query = queryr2(node*2, nl, mid, ql, qr, ind);
- if (left_query == -1)
- return queryr2(node*2+1, mid+1, nr, ql, qr, ind);
- else
- return left_query;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement