Editorial for OTHS Coding Competition 3 (Mock CCC) S4 - Magic Library
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
,Using a square root decomposition approach with lazy propagation, is divided into about
blocks, each with a size of approximately
. For each block, maintain a frequency array
, where
represents the number of books labeled
in that block. Additionally, keep track of a variable
, initially set to
, representing whether the entire block's books all have a label of
.
When updating a range to
, there will be at most
blocks fully covered by the range and at most
blocks that are partially covered. For fully covered blocks, update their value
to
. For partially covered blocks, if
, update
and
based on
(eg.
block size) and set
back to
. Then update the individual books. A single update takes
time.
A similar approach is used to query the range for occurrences of
. For fully covered blocks, if
, add the block size to the count. Otherwise, add
. For partially covered blocks, if
, update
and
based on
and set
back to
. Then compare the individual books with
and add the occurrences accordingly. A single query takes
time.
Comments