QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 512 MB Puntuación total: 100

#4394. 键盘侠

Estadísticas

有些参赛者在网上说他们热爱多校训练,难道其他人都没有键盘吗?

你一定是那个键盘坏得很严重的人。当你按下一个键时,它会随机触发多次。

给定一个字符 $ch$ 和一个整数 $k$,这意味着你按了一次字母数字键 $ch$,但它触发了 $k$ 次,并且 $k$ 个字符 $ch$ 会被添加到缓冲区末尾。

给定一个字符 - 和一个整数 $k$,这意味着你按了一次退格键,它触发了 $k$ 次,从末尾删除 $k$ 个字符(如果字符数量少于 $k$,缓冲区将被清空)。

给定按时间顺序排列的操作,你能输入你的目标文本吗?也就是说,是否存在某个时刻,你的目标文本是你缓冲区字符的子串?回答 'yes' 或 'no'。(在形式语言理论和计算机科学中,子串是字符串中连续的字符序列。)

输入格式

第一行包含一个整数 $T$,表示有 $T$ 组测试数据。对于每组数据:

第一行包含两个整数 $n, m$,$n$ 表示目标文本的长度,$m$ 表示按键的次数。

第二行包含一个长度为 $n$ 的字符串,仅包含小写字母。

接下来的 $m$ 行,每行包含一个字符 $ch$ 和一个整数 $k$,其含义如上所述。

$1 \le n, m \le 2 \times 10^5, 0 \le k \le 10^9, \sum n + m \le 10^6$

输出格式

对于每组数据,输出 'yes' 或 'no',不带引号。

样例

输入 1

3
6 6
iloveu
i 1
l 1
o 1
v 1
e 1
u 0
6 10
imfive
u 10
- 20
i 1
m 1
f 1
i 1
v 5
- 4
e 2
- 2
4 4
abab
a 2
b 2
- 3
b 1

输出 1

no
yes
no

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.