Editorial for Valentine's Day '19 S2 - Ctudor's Cute Cacti
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.
Author:
For the first subtask, we can brute force.
Time Complexity:
For the second subtask, we can observe a few things. Firstly, notice that for every update event, only a row and a column is updated. Thus, we can keep track of the rows and columns separately. Let represent the number of times row was updated, and let represent the number of times column was updated. For an update event, we only need to increment and by one. For a query event, we simply add , and modulo by .
However, notice that position is counted twice in both the row and the column. Thus, we need to use a hashmap or a map to keep track of the number times position was the actual position that was updated, and subtract that value.
Time Complexity: or
Comments