Editorial for JOI '21 Open P1 - Crossing
Submitting an official solution before solving the problem yourself is a bannable offence.
We associate J
, O
, I
with ,
,
, respectively, and consider a gene sequence as an
-dimensional vector over
the residue field
. Let
be the gene sequence obtained from
by crossing. Note that
holds. By induction on the number of crossing operations, it can be shown that a gene sequence which can be
obtained from
is written as a linear combination of the form
for some
satisfying
. This is a necessary condition. There are
possible choices of tuples
,
and all of them are obtained as follows. Hence this is also a sufficient condition.
- If
, it is the sequence
itself.
- If
, it is the sequence
itself.
- If
, it is the sequence
itself.
- If
, it is the sequence
.
- If
, it is the sequence
.
- If
, it is the sequence
.
- If
, it is the sequence
.
- If
, it is the sequence
.
- If
, it is the sequence
.
Therefore, calculating the above gene sequences in advance, we need to compare them with each sequence
. Under the constraints of Subtask 3, it can be done in time by a simple comparison of strings.
In the following, we fix a gene sequence . We want to decide whether it coincides with each sequence
or not. This immediately gives a solution of Subtask 2. Combining it with the above consideration, we obtain a
solution of Subtask 4.
For simplicity, we assume the integer is a power of
. We put the additional data
on each node of a segment tree. Defining lazy propagation functions appropriately, we can construct a lazy
propagation segment tree with
for every evaluated node . The time complexity of this algorithm is
per query. It is sufficiently
fast to solve this task.
Comments