Range count with threshold
Your task
Given a static integer array and a list of [l, r, x] queries, return for each query the count of elements in the inclusive range arr[l..r] whose value is <= x. Build a merge-sort tree (a segment tree whose every node stores its segment's elements in sorted order); a query decomposes [l, r] into O(log n) nodes and binary-searches each sorted list for x, giving O(log^2 n) per query. Return the list of counts in query order.
Examples
range_count_leq(arr: list[int], queries: list[list[int]]) -> list[int]Example 1
Input
range_count_leq([1, 5, 2, 8, 3, 7], [[0, 5, 4], [1, 3, 5], [2, 2, 2], [0, 5, 10]])Output
[3, 2, 1, 6]