![]() |
||||||||||
|
||||||||||
Keyboard WarriorTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 601 Accepted Submission(s): 159 Problem Description Some contestants said on the Internet that they love Multi-University Training, did the rest of them have no keyboards? You must be the one whose keyboard is badly broken. When you press a key, it triggers a random number of times. Given a character $ch$ and an integer $k$, it means you press an alphanumeric key $ch$ only once, but it triggers $k$ times, and $k$ character $ch$ will be added to the end of the buffer. Given a character '-' and an integer $k$, it means you press the backspace key, it triggers $k$ times, delete $k$ characters from the end (If the number of characters is less than $k$, the buffer will be cleared). Given the operations in chronological order, could you input your target text? Which means whether there is a time, your target text is a substring of your buffer characters? Answer 'yes' or 'no'. (In formal language theory and computer science, a substring is a contiguous sequence of characters within a string.) Input First line has one integer $T$, indicating there are $T$ test cases. In each case: First line has two integers $n, m$, $n$ indicates the length of your target text, $m$ indicates the number of times you press the key. Second line has a string of length $n$, which contains only lowercase letters. For next $m$ lines, each line has a character $ch$ and an integer $k$, their meanings are described above. $1 \leq n, m \leq 2 \times 10^5, 0 \leq k \leq 10^9, \sum {(n+m)} \leq 2\times 10^6$ Output In each case, print 'yes' or 'no', without quote. Sample Input
Sample Output
Source | ||||||||||
|