Portal Gun
Time limit4sMemory limit1024 MB
Given a string with single-character updates and global letter replacements, the task is to answer whether two equal-length substrings match after each query.
- Level
Medium7 of 10
- Topics
- String matching, Segment tree, Hash map
- Solved
- No attempts yet
Statement
Rick knows perfectly well that Morti cannot be trusted with a portal gun, but Morti has pestered him for his own portal gun for so long that Rick gave in and built him a mini version.
To make Morti improve (or simply to make it harder for him to use), Rick made the device quite convoluted. The portal gun has parameters, each taking a value from 'a' to 'z'. Let denote the parameter with number .
In one action, Morti can:
- choose a parameter index from to and change its value to another value from 'a' to 'z';
- choose two values and from 'a' to 'z' and replace the value of all parameters whose current value is with ;
- check whether portals can be created at locations and (where and ). For this, the parameters at positions must match elementwise the parameters at positions , that is, the following must hold:
Morti is not very clever, so comparing parameter sequences quickly is hard for him, and he does not want to break the portal gun by accident. For each action of the third type, determine whether he can create the portals at the requested locations.
Input
The first line contains a string of length consisting of lowercase Latin letters, the initial values of the parameters ().
The next line contains a single integer , the number of actions Morti performs ().
Each of the next lines describes an action:
1: set the -th parameter to value (; 'a' 'z').2: replace every value equal to among all parameters with ('a' 'z').3: check whether portals can be created at locations and (; ; ).
Output
For each action of the third type, print YES on a separate line if Morti can perform it, and NO otherwise.