Editorial for DMOPC '19 Contest 2 P3 - Selection
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
For subtask 1, a simple brute force algorithm will suffice. For each query, we can sort the subarray, take the
Time complexity:
For subtask 2, we can build a Binary Indexed Tree (BIT) over our array and update it accordingly. For each query, we use our BIT to find the number of 1
s in our subarray. If this is more than 1
. Otherwise, it has goodness 0
.
Time complexity:
For subtask 3, we instead build a BIT for the number of elements for each possible
Time complexity:
Comments
A segment tree for number frequency would suffice as well.
"26 pbds" - ChrisT