CF1742F.Smaller

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alperen has two strings, ss and tt which are both initially equal to "a".

He will perform qq operations of two types on the given strings:

  • 1    k    x1 \;\; k \;\; x — Append the string xx exactly kk times at the end of string ss. In other words, s:=s+x+⋯+x⏟k timess := s + \underbrace{x + \dots + x}_{k \text{ times}}.
  • 2    k    x2 \;\; k \;\; x — Append the string xx exactly kk times at the end of string tt. In other words, t:=t+x+⋯+x⏟k timest := t + \underbrace{x + \dots + x}_{k \text{ times}}.

After each operation, determine if it is possible to rearrange the characters of ss and tt such that ss is lexicographically smaller†^{\dagger} than tt.

Note that the strings change after performing each operation and don't go back to their initial states.

†^{\dagger} Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. A formal definition is as follows: string pp is lexicographically smaller than string qq if there exists a position ii such that pi<qip_i \lt q_i, and for all j<ij \lt i, pj=qjp_j = q_j. If no such ii exists, then pp is lexicographically smaller than qq if the length of pp is less than the length of qq. For example, abdc<abe\texttt{abdc} \lt \texttt{abe} and abc<abcd\texttt{abc} \lt \texttt{abcd}, where we write p<qp \lt q if pp is lexicographically smaller than qq.

阿尔佩伦有两个字符串 ss 和 tt,初始时二者均等于 "a"。

他将对这两个字符串执行 qq 次操作,操作分为两类:

  • 1    k    x1 \;\; k \;\; x —— 将字符串 xx 恰好重复 kk 次并拼接到字符串 ss 的末尾。即:s:=s+x+⋯+x⏟k 次s := s + \underbrace{x + \dots + x}_{k \text{ 次}}。
  • 2    k    x2 \;\; k \;\; x —— 将字符串 xx 恰好重复 kk 次并拼接到字符串 tt 的末尾。即:t:=t+x+⋯+x⏟k 次t := t + \underbrace{x + \dots + x}_{k \text{ 次}}。

每次操作后,请判断是否可能通过重新排列 ss 和 tt 中的字符(各自独立重排),使得重排后的 ss 在字典序上严格小于重排后的 tt。

注意:字符串在每次操作后都会发生改变,且不会恢复至初始状态。

†^{\dagger} 简单来说,字典序即单词在字典中的排列顺序。其形式化定义如下:字符串 pp 在字典序上小于字符串 qq,当且仅当存在某个位置 ii,使得 pi<qip_i \lt q_i,且对所有 j<ij \lt i 均有 pj=qjp_j = q_j;若不存在这样的 ii,则当且仅当 pp 的长度小于 qq 的长度时,pp 在字典序上小于 qq。例如,abdc<abe\texttt{abdc} \lt \texttt{abe} 且 abc<abcd\texttt{abc} \lt \texttt{abcd},其中我们用 p<qp \lt q 表示 pp 在字典序上小于 qq。

输入格式

The first line of the input contains an integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains an integer qq (1≤q≤105)(1 \leq q \leq 10^5) — the number of operations Alperen will perform.

Then qq lines follow, each containing two positive integers dd and kk (1≤d≤21 \leq d \leq 2; 1≤k≤1051 \leq k \leq 10^5) and a non-empty string xx consisting of lowercase English letters — the type of the operation, the number of times we will append string xx and the string we need to append respectively.

It is guaranteed that the sum of qq over all test cases doesn't exceed 10510^5 and that the sum of lengths of all strings xx in the input doesn't exceed 5⋅1055 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 qq(1≤q≤1051 \leq q \leq 10^5)—— Alperen 将执行的操作次数。

接下来是 qq 行,每行包含两个正整数 dd 和 kk(1≤d≤21 \leq d \leq 2;1≤k≤1051 \leq k \leq 10^5)以及一个由小写英文字母组成的非空字符串 xx —— 分别表示操作类型、字符串 xx 的追加次数以及需要追加的字符串。

保证所有测试用例的 qq 总和不超过 10510^5,且输入中所有字符串 xx 的长度总和不超过 5⋅1055 \cdot 10^5。

输出格式

For each operation, output "YES", if it is possible to arrange the elements in both strings in such a way that ss is lexicographically smaller than tt and "NO" otherwise.

对于每个操作,如果能够以某种方式重新排列两个字符串中的元素,使得 ss 的字典序小于 tt,则输出 “YES”,否则输出 “NO”。

输入输出样例

  • 输入#1

    3
    5
    2 1 aa
    1 2 a
    2 3 a
    1 2 b
    2 3 abca
    2
    1 5 mihai
    2 2 buiucani
    3
    1 5 b
    2 3 a
    2 4 paiu

    输出#1

    YES
    NO
    YES
    NO
    YES
    NO
    YES
    NO
    NO
    YES

说明/提示

In the first test case, the strings are initially $s = $ "a" and $t = $ "a".

After the first operation the string tt becomes "aaa". Since "a" is already lexicographically smaller than "aaa", the answer for this operation should be "YES".

After the second operation string ss becomes "aaa", and since tt is also equal to "aaa", we can't arrange ss in any way such that it is lexicographically smaller than tt, so the answer is "NO".

After the third operation string tt becomes "aaaaaa" and ss is already lexicographically smaller than it so the answer is "YES".

After the fourth operation ss becomes "aaabb" and there is no way to make it lexicographically smaller than "aaaaaa" so the answer is "NO".

After the fifth operation the string tt becomes "aaaaaaabcaabcaabca", and we can rearrange the strings to: "bbaaa" and "caaaaaabcaabcaabaa" so that ss is lexicographically smaller than tt, so we should answer "YES".

在第一个测试用例中,字符串初始为 $s = $ "a" 和 $t = $ "a"。

第一次操作后,字符串 tt 变为 "aaa"。由于 "a" 本身已字典序小于 "aaa",因此该次操作的答案应为 "YES"。

第二次操作后,字符串 ss 变为 "aaa",而此时 tt 也等于 "aaa",因此无法通过重排 ss 使其字典序小于 tt,答案为 "NO"。

第三次操作后,字符串 tt 变为 "aaaaaa",而 ss 已字典序小于它,因此答案为 "YES"。

第四次操作后,ss 变为 "aaabb",而无法通过任何重排使其字典序小于 "aaaaaa",因此答案为 "NO"。

第五次操作后,字符串 tt 变为 "aaaaaaabcaabcaabca",此时我们可以将字符串重排为:"bbaaa" 和 "caaaaaabcaabcaabaa",使得 ss 字典序小于 tt,因此答案为 "YES"。

输入解题思路,AI测评打分。不知道怎么写?

首页