Moeebius
2024-10-14 16:11:22
Operation 1 denotes "Choose a digit and delete it", and operation 2 denotes deleteing all the remaining digits in one go.
Hint 1: When operation 2 is better than operation 1?
Hint 2: Enumerate from right to left.
It's easy to notice that we won't leave too much digits for operation 2. Furthermore, the number of left digits,
Consider dynamic programming. Let
Let
Thus, we can solve this problem in
The hardest problem in this round!
Operation 1 denotes subtraction, and operation 2 denotes addition.
Hint 1: Adjust the order of the operations.
Hint 2: Can you determine whether a sequence of operation 1 is valid?
Hint 3: Use binary search.
We need some observations to make this problem easier.
Observation 1
One can always use all operation 1 before any operation 2.
It's straightforward, so I omit the proof.
However, it leads to the first key observation:
Observation 2
Let
a'_i be the temperature of vertexi after we use up operation 1.The answer is yes (i.e.
Huoyu
) if and only if\forall j \in \text{son}_i, a'_j \le a'_i , anda'_1 \le 0 .
To proof it, consider the root. Since we can only increase the temperature using operation 2,
Now the temperature of root is
Let
We need to check whether we can managed to satisfy the following inequalities:
However, it seems impossible to maintain the information, since
Observation 3
for all vertex
i , there exists an interval[l_i, r_i] (possibly empty), such thatx_i = p is valid (with all the constraints inside subtreei )\iff p \in [l_i,r_i] .
The proof also needs induction.
Firstly,
It's obvious that we only need to consider the case where there aren't any empty intervals.
Suppose
There must exist a
For
Thus,
One corner case is that
Given observation 3, a fan of Um_nik should immediately come up with binary search.
In detail, we can first compute
Enumerate
Otherwise, we can compute bound of
Thus, we can solve the problem in
Please take care of the bound while binary searching, and maybe __int128
is neccessary in some cases.
Hint 1: solve the 2/5 scored problem, i.e. come up with a solution without maximizing k.
Hint 2: solve Special Property B, i.e.
\Sigma=2 .This is a deterministic approach, which needs some case work.
Consider when the answer is no (i.e. Shuiniao
).
It's obvious that such condition is sufficient.
We can also show that such condition are necessary, by giving a construction of the answer sequence.
After we exclude the situation with no solution, one should consider how to maximize anti2.ans
one should notice almost every subsequence has length
So, if we only need to calculate k, one can easily come up with a greedy solution: Every time, we pick 2 diffrent characters with the maximum and the second maximum times of occurrence. Then we pack the first occurrence of both characters into a subsequence, and remove such 2 occurrence.
It's not hard to proof that k is maximized. If
Obviously, only 1 kind of character will remain in a
be such character.
We enumerate from a
before
It can be shown that, after this stage, only a trailing sequence of a
(possibly empty) will remain. Every a
before any character other than a
will be removed.
Let a
s in the subsequence which a
in stage 0, let
Let a
sequence.
If there exists an a
after
Otherwise, if there exists more than
Let
a
after a
with a
s before it, and nothing behind it, and a
(only Otherwise, there will be no solution, as the string must satisfy one of the condition given above.
Thus, we solved this problem in
Hint 1: solve Special Property D.
Hint 2: consider sqrt balancing.
It is not hard for one to notice, given
Consider maintaining
Suppose we move to
So the problem is translated into a form of 2D counting, because we only need to count
However maintaining
Use the balancing trick. For all vertices