We apologize for the malfunction of the judge due to glitched Q2 grader and test cases during the contest.
We will avoid such issues from happening again.

C2391

Subtask 1 (40%)

Pure implementation, just simulate the game for each of the $Q$ rounds.
Precompute 3000x3000 array with long long causes MLE.

Full solution

Note that we don't need to simulate for each query. We only need to compute the offset $\Delta_k$ the ball has shifted for each $1 \leq k \leq 2 × 10^5$.
And $e_i=1+(a_i+\Delta_{k_i}-1)$ $mod$ $N$.

C2392

Subtask 1 (3%)

Brute force all index pairs. Time complexity: $O(\frac{N(N-1)}{2}!)$.

Full solution

The swapping of seats forms a number of disjoint cycles:
  • Pupil $\#2$ moves from seat $\#2$ to $\#4$.
  • Pupil $\#1$ moves from seat $\#4$ to $\#1$.
  • Pupil $\#3$ moves from seat $\#3$ to $\#5$.
  • ...
  • Pupil $\#73$ moves from seat $\#24$ to $\#2$
Core observation: $T \leq 2$ for all cases. Why?
Consider a cycle $C$:
if $|C|=2$, only one swap is required.
Otherwise, one can split it into $\frac{|C|}{2}$ cycles of size $2$ (see below).
The rest is outputting the class numbers carefully.
How do we find and output labels in linear time?
  • Create a mapping $mv[1..N]$ and also its inverse $inv$. The pupil at seat $\#i$ initially moves to seat $\#mv[i]$.
  • Notice that if we select and swap indices $i$ and $j$ with distance $2$ in the move sequence, $C$ is splitted into $2$ disjoint new cycles: one with length $2$ and the other have length $|C|-2$.
  • The length $2$ cycle contains $mv[i]$ and $j$. It can be swapped in the next minute.
  • The other has $i$ swapped and cannot move again. However, you can choose $i=inv[i]$ and $j=mv[i]$ and repeat the process until $|C| \leq 2$.
  • At last, the entire cycle is shifted within $2$ minutes.
  • Remember to output $A[i]$ and $A[j]$ instead of $i$ and $j$.
For subtask 2 any $O(N^2)$ algorithm is accepted.
For subtask 3, there are $gcd(N,K)$ cycles. the $j$-th one contains all $i ≡ j$ $(mod$ $gcd(N,K))$.

C2393

Subtask 1 (10%)

Since $K=1$, all jewels have to have the same weight.
  • If $A[i] \geq N$, output 0
  • If $W[i] = B$, output the sum of largest $M$ jewels with the largest being $N-A[i]$.
  • Else output the sum of largest $M$ jewels.

Subtask 2 (20%)

Observation:
$W[i] = W[(i+K-1)$ $mod$ $N+1]$
If a robber took jewels from range $[l, l+K-1]$ and another took from range $[l+K, l+2K-1]$, then $\sum_{i=l}^{l+K-1} W[i] = \sum_{i=l+K}^{l+2K-1}W[i]$
If a robber took jewels from range $[l+1, l+K]$ and another took from range $[l+K+1, l+2K]$, then $\sum_{i=l+1}^{l+K} W[i] = \sum_{i=l+K+1}^{l+2K}W[i]$
By subtracting the bottom formula with the top, we can obtain that $W[l+K]-W[l] = W[l+2K]-W[l+K]$.
However, it is trivial that $W[l+K]-W[l]\neq0$ is impossible as the largest/smallest $W[i]$ would not have another index $j$ which $W[j]$ is larger/smaller.

With this observation, simply brute force the number of $W[i]$ in a cycle and use greedy and iterate through the array to calculate the answer.

Subtask 3 (30%)

Use the observation from before, as $N$ $mod$ $K = 0$, there are $N/K$ jewels in a cycle. Use simple math to calculate the answer.

Subtask 4 (20%)

It can be observed that the cycle length is $gcd(N, K)$.

Full solution

When $W[i]=B$, apart from the cycles that are swapped out, extra calculation has to be done to take care of these jewels.

C2394

Subtask 1 (10%)

The problem can be reduced to finding pairs of numbers from $[-1, 0, 1]$ to create the binary forms of $|S_x-E_x|$ and $|S_y-E_y|$.
Greedily assign the pairs of numbers.

Subtask 2 (15%)

As there is only 1 bit in both $|S_x-E_x|$ and $|S_y-E_y|$, brute force the amount of $-1$. Time complexity: $O(N^2)$

Subtask 3 (15%)

Brute force on assignments of letters. Time complexity: $O(3^{14})$

Subtask 4 (20%)

Brute force on assignments of $1$. Time complexity: $O(2^N)$

Full solution

Use branch cutting and observations to do it. Time complexity: $O($no idea$)$