|
||||||||||
Auto-correctionTime Limit: 5000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 66 Accepted Submission(s): 36 Special Judge Problem Description It is preferrable to read the pdf statment. Cuber QQ is poor in English writing, and in the process of preparing this contest, he realized that he is making too many grammar mistakes that an auto-correction engine is needed. Instead of using online tools like ''Microsoft Aim Writing'' or ''Grammarly'', he was interested in building a new engine on his own. In particular, he adopted a naive sequence-to-sequence model, that takes a sequence, which is usually a sentence, and predict for each token, which is usually a word or character, whether there is something wrong with it, and if yes, what it should be replaced with. Here are several examples:
You might notice that, in this sequence-to-sequence model, the phrase to replace should be at least one token, and the target should be at least one token too. This is related to the architecture and training approach of his model. We will not go into too many machine learning details here, as it will make the statement tedious. The problem is however, the training data does not conform with such format. In the training data, a sequence with flaws can be annotated with three types of annotations: add, delete and replace. Concretely,
All the annotations are applied directly to the original sequence, i.e., the indices like $l$ and $r$ refers to the original indices, instead of the indices after modification. As ''add'' and ''delete'' will not be supported in the model, the preprocessing step needs to rewrite all ''add'' and ''delete'' with ''replace''. Furthermore, as there are many ways to achieve such goal, Cuber QQ wants to find the cheapest way, i.e., after the annotation rewriting, the total number of replaced tokens should be as minimum as possible. If there is a tie, the number of annotation records should be as minimum as possible. In case there is still a tie, any one of them is acceptable. Input The input starts with an integer $t$ ($1 \le T \le 50~000$), denoting the number of test cases. For each test case, the first line contains two space-separated integers $n$ and $q$ ($1 \le n, q \le 2~000$), where $n$ is the number of tokens in the original sequence, and $q$ is the number of original annotations. In the next line, $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) are presented, denoting the sequence. The $i$-th of the following $q$ lines is in one of the 3 formats:
It is guaranteed that $l_i \le l_{i+1}$ for all $1 \le i < n$, and $l_i = l_{i+1}$ only happens when $i$ is $A$ and $i+1$ is not, which means, there is at most one ''add'' at the same position. The annotations are non-overlapping, i.e., $r_i \le l_{i+1}$ for all $1 \le i < n$ if $r_i$ is available for $i$. Furthermore, the corrected sequence after applying all the annotations is not empty. It is guaranteed that for each test case, the corrected sequence is neither empty nor longer than $4~000$. The sum of $n$ and the total length of corrected sequences both do not exceed $50~000$. Output For each test case, in the first line output two space-separated integers: minimum number of tokens that will be replaced, $x$, and minimum number of converted annotations, $y$. In the following $y$ lines, you can output the annotations in any order. $R$ should be omitted as it is the only type that is allowed. The annotations should be non-overlapping, non-empty and follow the exactly same format as input. NoteFor the first test case, $[2, 3]$ is replaced with $1$, $[4, 6]$ is replaced with $2,3$, and the corrected sequence is $1,1,2,3$. The optimal correction with only $R$ is to replace $[2, 6]$ with $1,2,3$. For the second test case, the corrected sequence is $1,2,4,6,5$. Although $A$ and $D$ cannot be used, if we merge the consecutive annotations, only 4 tokens need to be replaced. In the third test case, we show that the corrected sequence can be longer than the original sequence, which is $2,1,2,3,4,5,5,6$. Sample Input
Sample Output
Source | ||||||||||
|