These are the prefix sum and hashing problems every placement candidate should be able to solve, from a plain range query to counting blocks in a table. State the brute force and its cost first. Then write the better version and check it against every test.