EGOI 2026 Editorial - Watering Plants
Task Author: Harry Zhang
Subtask 1
In this subtask, there is only one day and one query for some resident
Subtask 2 - No ! type queries
Since there are no ! type queries, the relative order of arrival times never changes: if resident ? query.
So for a given day
, if . , if .
Subtask 3 - N = 2
In this subtask, only resident 1 ever waters the plants for resident
0. When iterating through the days, we keep track of a number
Subtask 4 - Solution
For each day, we directly track and update for everyone how many times they have watered the plants for resident below them.
Maintain
- For each
with : if , increment by . - Process the event at the end of day
:- For "! i t", set
. - For "? i", output
.
- For "! i t", set
This runs in
Subtask 5
The key observation for this subtask and the full solution is that the watering relationship for pair
In this subtask, every resident changes their return time at most once.
For each resident
Let
- from time
to the first change , where the number is if or otherwise - from the earlier change
to the second change , where we need to distinguish two cases:- for
< : the number is if or otherwise - otherwise, it is
if or otherwise
- for
- from the later change
to time , where the number is if or
Summing all numbers gives us the solution.
This runs in
Full Solution
Using a similar approach from the previous subtask, we could
accumulate the correct numbers for all time segments between consecutive
changes for every ? query.
However, this is too slow since return times can now change often.
Instead, we now update
- There is a query for
, - the schedule of resident
changes or - the schedule of resident
changes.
For each resident
, the current arrival time , the number of days resident has watered for resident , the last day when was updated (initially )
When we need to update some
The solution then works as follows:
When we process an update event ! i t at the end of day
When we process a query event ? i at the end of day
This solution runs in