Editorial - 2022 Mini Contest 0
C2201 - Sussy Rock
The task is to find the number of multiples of $N$ between $A$ and $B$.
Let $f(x)$ be the number of multiples of $N$ between $1$ and $x$. We have $f(x) = \lfloor \frac{x}{N} \rfloor$.
The answer is $f(B) - f(A - 1)$.
C2202 - Sussy Substring
Use a stack to store the resulting string. Iterate through each character in $S$. If it combines with the character on the top of the stack to form a sussy substring, pop from the top of the stack. Repeat this until the current character and the character on the top of the stack do not form a sussy substring, then push the current character onto the stack. The stack stores the resulting string at last.
Time complexity: $O(|S|)$
C2203 - Sunnie's Array
It is not feasible to construct the array $B$ as it contains $\frac{N(N-1)}{2}$ elements.
Note that $1 \le A_i \le 10^3$ as mentioned in the constraints. This means that there will be at most $10^3$ unique values in $A$.
Let's construct a counting array for $A$, i.e. $c_i$ = number of occurrences of $i$ where $1 \le i \le 10^3$.
Iterate over each pair $(i, j)$ where $1 \le i \le j \le 10^3$.
If $i = j$ and $i^2$ contains the digit $K$, then add $\frac{c_i(c_i - 1)}{2}$
(the number of pairs you can choose from $c_i$ elements) to the answer.
If $i \neq j$ and $i \times j$ contains the digit $K$, add $c_i \times c_j$ to the answer.
Time complexity: $O(\max(A)^2)$
C2204 - School of Imposture
Subtasks 1 and 2
Create $G$ prefix sum arrays: let $p[g][i]$ be the number of students with ID
between $1$ and $i$ who are enrolled in grade $g$.
You can answer each query in $O(1)$ by calculating $p[K][B] - p[K][A - 1]$.
Subtask 3
Updating the grade of each student after each question would be too slow.
Instead, figure out the value of $K$ which would correspond to the grades of the students in the initial year.
You can do this using modular arithmetic.
Time complexity: $O(GN + Q)$