Problem F
Daily Playlist
Hugo is obsessed with organizing his music. Unfortunately, he is also extremely indecisive. He has $N$ playlists, numbered from $1$ to $N$. Each playlist stores an ordered sequence of songs, and each song is represented by a single lowercase English letter ’a’-’z’. Hugo is not very disciplined, he often adds the same song multiple times because “what if I want to hear it again immediately?"
Hugo changes his mind very often, over the next $T$ days, he performs exactly one operation per day. Some days he reorganizes his playlists for no clear reason. Other days he suddenly feels like listening to a specific set of songs and wants to check whether a playlist satisfies his current mood. There are two types of operations:
1. MOVE x i y. Hugo removes the $i$-th song ($1$-indexed) from playlist $x$ and appends it to the end of playlist $y$.
2. PLAY x s. Hugo is currently in the mood for the songs listed in string $s$.
He wonders whether playlist $x$ contains all distinct songs appearing in $s$. The order of letters in $s$ does not matter. Duplicate letters in $s$ should be ignored. Each distinct letter in $s$ must appear at least once in playlist $x$. For every PLAY operation, print ‘YES‘ if Hugo can happily listen to all the songs he wants, and ‘NO‘ otherwise. Hugo may change his mind tomorrow anyway.
Note that each playlist has at most 100 songs as the app does not allow longer playlists. Hugo will only apply valid operations that do not cause a playlist’s length to exceed 100 songs.
Input
The first line contains two integers $N$ and $T$ ($1 \le N, T \le 10^4$). The next $N$ lines describe the initial playlists. Each line contains a non-empty string of length at most $100$ consisting only of lowercase English letters ’a’-’z’, representing the songs in that playlist in order. Each of the following $T$ lines describes one operation in one of the following formats:
MOVE x i y or
PLAY x s
It is guaranteed that: for every MOVE x i y, the playlist $x$ contains at least $i$ songs at the time of the operation, and the move does not cause playlist $y$ to have more than $100$ songs.
Output
For each PLAY operation, output a single line containing: ’YES’ if playlist $x$ contains all distinct letters in $s$, or ’NO’ otherwise.
| Sample Input 1 | Sample Output 1 |
|---|---|
2 4 abca de PLAY 1 ab PLAY 2 ad MOVE 1 2 2 PLAY 2 ab |
YES NO NO |
| Sample Input 2 | Sample Output 2 |
|---|---|
3 4 abc aaa xyz PLAY 1 ac MOVE 2 1 1 PLAY 1 a PLAY 3 xz |
YES YES YES |
