A. Number Replacement

Solution:

Obviously each number can only be replaced by the same letter, so we only need to open a Map to check whether any number has been replaced by two different letters.

Java

C++

B. Even-Odd Increments

Solution:

Count the number and sum of odd and even numbers. For each query, we just need to multiply x by the number and add it to the sum.
Also note that when x is odd, the parity is changed. Therefore, the number and sum need to be added to another type.

Java

C++

C. Traffic Light

Solution:

Just do the simulation and record the indexes of all the green lights. Then check from left to right. As the pointer moves to the right, the corresponding green lights' pointer will gradually move to the right.
When it is found that the pointer of green light can no longer move to the right, it means that it needs to enter the next cycle.

Java

C++

D. Divisibility by 2^n

Solution:

First look at how many 2s are in all a[i], and then check how many 2s are in each i.
If there are not enough 2 in all a[i], then sort i, and choose i with more 2 as much as possible.

Java

C++

E. Divisible Numbers (Easy/Hard)

Solution:

Obviously, if the condition is changed to $a \leq x \leq c$ and $b \leq y \leq d$, then just make x=a, y=b directly.
Therefore, it is naturally conceivable that we multiply x and y by a number as small as possible. For example 2.

Further we can find that if the initial values of x and y are a and b respectively. We give y a factor of x, give x a factor of y, and then multiply the reduced number by a number as small as possible to make it larger than its original value, which will give a better result than multiplying directly by 2.
For example, a is divisible by 2 and b is divisible by 3. Then exchange factors 2 and 3, so $x=\frac 3 2 \cdot a$, $y=\frac 2 3 \cdot b$. So x only increases by a factor of 1.5. y needs to be multiplied by some number to exceed b.

So we enumerate the cases where all the factors of x and y are exchanged with each other.

Java

C++

F. MEX vs MED

Solution:

Obviously, if mex is greater than med, then all values smaller than med() must appear. That is to say, all numbers before the median must all appear, and other numbers don't matter.
So for a given length, the result of its med() must be fixed, and all values less than or equal to med() must appear.

So we only need to enumerate the length. For each length, we calculate the minimum interval that contains all the numbers that must appear, and then calculate how many ways to expand to the specified length based on this minimum interval.

Java

C++