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.
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 . For and , you can use a balanced binary search tree or simply binary search for their occurrences in a precomputed list.
Time Complexity:
Comments
What do you mean when you say a "precomputed list." Like what are you precomputing?
You can precompute a list of all the array indices that a given value occurs at.