Editorial for DMOPC '15 Contest 4 P4 - Great Sequence


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

We use prefix sum to check whether the subarray's sum is greater than K. For a and b, you can use a balanced binary search tree or simply binary search for their occurrences in a precomputed list.

Time Complexity: \mathcal{O}(N+Q \log N)


Comments


  • 1
    kelvin01732  commented on June 8, 2022, 6:28 p.m.

    What do you mean when you say a "precomputed list." Like what are you precomputing?


    • 1
      thomas_li  commented on June 8, 2022, 9:28 p.m.

      You can precompute a list of all the array indices that a given value occurs at.