Editorial for DMOPC '19 Contest 6 P4 - Grade 12 Math
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
For the first subtask, it suffices to maintain an array , where represents the opinion of the classmate. To handle updates, simply increment/decrement the given index, and to handle range queries, loop over the range and count how many of the specified values exist in that range.
Time complexity:
For full marks, we maintain a segment tree where each node contains a map which maps the opinions in that range to their count. Because all values are initialized to , and we only have to handle increment and decrement updates, there can be at most distinct values in the whole segment tree at any given time, which is enough to justify the overhead of having a map at each node. However, to leverage this, special attention must be given to delete keys in the map which are not in use.
Time complexity:
Comments