#B3748. Document Combination and Similarity Check
Document Combination and Similarity Check
Document Combination and Similarity Check
Fusu has not slept for hours while working on her theoretical computer science assignment. To speed up her sleep, she has found documents, where the -th document is a string . She plans to combine these documents using the following two operations:
1. 1 x y
: Concatenate document to the end of document , then delete (it will never be used in later operations).
2. 2 x y
: Query whether document and document are similar.
Two documents are defined to be similar if one of them can be rearranged (i.e. its characters permuted) to become exactly equal to the other. In other words, they are anagrams of each other.
Note that the query operation does not modify any document.
inputFormat
The first line contains two positive integers and , representing the number of documents and the number of operations respectively. The next lines each contain a non-empty string . The following lines each describe an operation in one of the following two forms:
- 1 x y
: Concatenate document to the end of document , and then delete .
- 2 x y
: Output 'YES' if document and are similar (anagrams), otherwise output 'NO'.
It is guaranteed that after a document is deleted via a type-1 operation, it will not appear in any later operation.
outputFormat
For each query operation (type 2), output a single line containing either 'YES' or 'NO', indicating whether the two specified documents are similar.
sample
3 3
ab
cd
abcd
1 1 2
2 2 3
2 3 2
YES
YES
</p>