Exam Rank Fenwick Problem

Exam Rank Fenwick Problem — ExecCode Hard DSA Practice

Solve the Exam Rank Fenwick problem on ExecCode. Free online hard DSA practice in Searching & Sorting. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Student scores sit in a row. A query asks how many scores in [l, r] are at most x (how many passed a cutoff). A merge-sort tree binary-searches each segment; a Fenwick on compressed values with Mo or offline sort also works. Each query [l, r, x] counts values <= x in the closed range. You are given: arr — scores queries — [l, r, x] Return one count per query. Equals count: a score equal to x is included.

Examples

Input {'arr': [2, 5, 1, 5], 'queries': [[0, 3, 5], [0, 3, 1], [1, 2, 4]]}; Output [4, 1, 1]. Input {'arr': [7, 8], 'queries': [[0, 1, 3]]}; Output [0]. Input {'arr': [0], 'queries': [[0, 0, 0]]}; Output [1]

Constraints

Inclusive indices x may be below every score

Practice Exam Rank Fenwick free on ExecCode. Browse DSA problems, topic map, and placement guides.