CF1840E.Character Blocking

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two strings of equal length s1s_1 and s2s_2, consisting of lowercase Latin letters, and an integer tt.

You need to answer qq queries, numbered from 11 to qq. The ii-th query comes in the ii-th second of time. Each query is one of three types:

  • block the characters at position pospos (indexed from 11) in both strings for tt seconds;
  • swap two unblocked characters;
  • determine if the two strings are equal at the time of the query, ignoring blocked characters.

Note that in queries of the second type, the characters being swapped can be from the same string or from s1s_1 and s2s_2.

给你两个等长的字符串 s1s_1 和 s2s_2,均由小写拉丁字母组成,以及一个整数 tt。

你需要回答 qq 个查询,查询编号从 11 到 qq。第 ii 个查询发生在第 ii 秒。每个查询为以下三种类型之一:

  • 将两个字符串中位置 pospos(下标从 11 开始)处的字符封锁 tt 秒;
  • 交换两个未被封锁的字符;
  • 判断在该查询时刻,忽略所有被封锁的字符后,两个字符串是否相等。

注意:对于第二种类型的查询,被交换的字符可以来自同一字符串,也可以分别来自 s1s_1 和 s2s_2。

输入格式

The first line of the input contains a single integer TT (1≤T≤1041 \le T \le 10^4) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of each test case contains a string s1s_1 consisting of lowercase Latin letters (length no more than 2⋅1052 \cdot 10^5).

The second line of each test case contains a string s2s_2 consisting of lowercase Latin letters (length no more than 2⋅1052 \cdot 10^5).

The strings have equal length.

The third line of each test case contains two integers tt and qq (1≤t,q≤2⋅1051 \le t, q \le 2 \cdot 10^5). The number tt indicates the number of seconds for which a character is blocked. The number qq corresponds to the number of queries.

Each of the next qq lines of each test case contains a single query. Each query is one of three types:

  • "1   pos1\ \ \ pos" — block the characters at position pospos in both strings for tt seconds;
  • "2   1/   ⁣2   pos1   1/   ⁣2   pos22\ \ \ 1/\;\!2\ \ \ pos_1\ \ \ 1/\;\!2\ \ \ pos_2" — swap two unblocked characters. The second number in the query indicates the number of the string from which the first character for the swap is taken. The third number in the query indicates the position in that string of that character. The fourth number in the query indicates the number of the string from which the second character for the swap is taken. The fifth number in the query indicates the position in that string of that character;
  • "33" — determine if the two strings are equal at the time of the query, ignoring blocked characters.

For queries of the first type, it is guaranteed that at the time of the query, the characters at position pospos are not blocked.

For queries of the second type, it is guaranteed that the characters being swapped are not blocked.

All values of pos,pos1,pos2pos, pos_1, pos_2 are in the range from 11 to the length of the strings.

The sum of the values of qq over all test cases, as well as the total length of the strings s1s_1, does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 TT(1≤T≤1041 \le T \le 10^4),表示测试用例的数量。

随后是各测试用例的描述。

每个测试用例的第一行包含一个由小写拉丁字母组成的字符串 s1s_1(长度不超过 2⋅1052 \cdot 10^5)。

每个测试用例的第二行包含一个由小写拉丁字母组成的字符串 s2s_2(长度不超过 2⋅1052 \cdot 10^5)。

两个字符串长度相等。

每个测试用例的第三行包含两个整数 tt 和 qq(1≤t,q≤2⋅1051 \le t, q \le 2 \cdot 10^5)。其中 tt 表示一个字符被封锁的时间(单位:秒);qq 表示查询次数。

接下来的 qq 行,每行对应一个查询。每个查询为以下三种类型之一:

  • “1   pos1\ \ \ pos” —— 将两个字符串中位置为 pospos 的字符同时封锁 tt 秒;
  • “2   1/   ⁣2   pos1   1/   ⁣2   pos22\ \ \ 1/\;\!2\ \ \ pos_1\ \ \ 1/\;\!2\ \ \ pos_2” —— 交换两个未被封锁的字符。查询中的第二个数表示第一个待交换字符所在字符串的编号(11 或 22);第三个数表示该字符在对应字符串中的位置;第四个数表示第二个待交换字符所在字符串的编号(11 或 22);第五个数表示该字符在对应字符串中的位置;
  • “33” —— 判断在当前时刻,忽略所有被封锁的字符后,两个字符串是否相等。

对于第一类查询,保证在查询发生时,位置 pospos 上的字符尚未被封锁。

对于第二类查询,保证待交换的两个字符均未被封锁。

所有 pospos、pos1pos_1、pos2pos_2 的取值范围均为 11 到字符串长度(含端点)。

所有测试用例中 qq 的总和,以及所有 s1s_1 字符串的总长度,均不超过 2⋅1052 \cdot 10^5。

输出格式

For each query of the third type, output "YES" if the two strings s1s_1 and s2s_2 are equal at the time of the query, ignoring blocked characters, and "NO" otherwise.

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes" and "YES" will be accepted as a positive answer.

对于每个第三种类型的查询,在查询时刻,若忽略被屏蔽的字符后两个字符串 s1s_1 和 s2s_2 相等,则输出 “YES”,否则输出 “NO”。

你可以以任意大小写形式输出每个字母(小写或大写)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均可被接受为肯定回答。

输入输出样例

  • 输入#1

    2
    codeforces
    codeblocks
    5 7
    3
    1 5
    1 6
    1 7
    1 9
    3
    3
    cool
    club
    2 5
    2 1 2 2 3
    2 2 2 2 4
    1 2
    3
    3

    输出#1

    NO
    YES
    NO
    YES
    NO

说明/提示

Let's look at the strings s1s_1 and s2s_2 after each of the qq queries. Blocked characters will be denoted in red.

First example input:

(codeforcescodeforces, codeblockscodeblocks) →\rightarrow (codeforcescodeforces, codeblockscodeblocks) →\rightarrow (codeforcescode\color{red}{f}orces, codeblockscode\color{red}{b}locks) →\rightarrow (codeforcescode\color{red}{fo}rces, codeblockscode\color{red}{bl}ocks) →\rightarrow (codeforcescode\color{red}{for}ces, codeblockscode\color{red}{blo}cks) →\rightarrow (codeforcescode\color{red}{for}c\color{red}{e}s, codeblockscode\color{red}{blo}c\color{red}{k}s) →\rightarrow (codeforcescode\color{red}{for}c\color{red}{e}s, codeblockscode\color{red}{blo}c\color{red}{k}s) →\rightarrow (codeforcescodef\color{red}{or}c\color{red}{e}s, codeblockscodeb\color{red}{lo}c\color{red}{k}s)

Second example input:

(coolcool, clubclub) →\rightarrow (cuolcuol, clobclob) →\rightarrow (cuolcuol, cbolcbol) →\rightarrow (cuolc\color{red}{u}ol, cbolc\color{red}{b}ol) →\rightarrow (cuolc\color{red}{u}ol, cbolc\color{red}{b}ol) →\rightarrow (cuolcuol, cbolcbol)

我们来观察每次执行 qq 个查询后字符串 s1s_1 和 s2s_2 的变化。被屏蔽的字符将用红色表示。

第一个样例输入:

(codeforcescodeforces, codeblockscodeblocks) →\rightarrow (codeforcescodeforces, codeblockscodeblocks) →\rightarrow (codeforcescode\color{red}{f}orces, codeblockscode\color{red}{b}locks) →\rightarrow (codeforcescode\color{red}{fo}rces, codeblockscode\color{red}{bl}ocks) →\rightarrow (codeforcescode\color{red}{for}ces, codeblockscode\color{red}{blo}cks) →\rightarrow (codeforcescode\color{red}{for}c\color{red}{e}s, codeblockscode\color{red}{blo}c\color{red}{k}s) →\rightarrow (codeforcescode\color{red}{for}c\color{red}{e}s, codeblockscode\color{red}{blo}c\color{red}{k}s) →\rightarrow (codeforcescodef\color{red}{or}c\color{red}{e}s, codeblockscodeb\color{red}{lo}c\color{red}{k}s)

第二个样例输入:

(coolcool, clubclub) →\rightarrow (cuolcuol, clobclob) →\rightarrow (cuolcuol, cbolcbol) →\rightarrow (cuolc\color{red}{u}ol, cbolc\color{red}{b}ol) →\rightarrow (cuolc\color{red}{u}ol, cbolc\color{red}{b}ol) →\rightarrow (cuolcuol, cbolcbol)

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

首页