公式

E - Quiz Competition: Qualifiers 解説 by en_translator


For each participant \(i\), define a length-\(K\) sequence \(X_i\) as

\(X_{i,j}=\begin{cases} 0 & \text{if }S_{i,j}=T_{j}\\ 1 & \text{if }S_{i,j}\neq T_{j}.\\ \end{cases}\)

If \(N=M\), the answer is No if and only if \(X_i=(1,1,1,\dots)\).

If \(N\neq M\), the queries can be interpreted as follows:

  • Flip \(X_{i,j}\), and determine if there are at most \(M\) entries among \(X_1,\dots,X_N\) that are lexicographically equal to or less than \(X_i\).

(One can see that this is equivalent to the original problem by determining the ranks for all \(N\) participants according to the described qualification steps.)

By managing \(X\) in a Trie, the removal, insertion, and counting operations required once each in each query can be processed in \(O(K)\) time, allowing an \(O((N+Q)K)\) solution.

Alternatively, the problem can be solved in \(O((N+Q\log N)K)\) using a data structure that manages the largest \(M\) elements using a priority queue or an ordered multiset. (Reference: ABC281E)