Under construction

Still being built. Things may change

Portal Gun

Time limit4sMemory limit1024 MB

Summary
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 nn parameters, each taking a value from 'a' to 'z'. Let pip_i denote the parameter with number ii.

In one action, Morti can:

  • choose a parameter index ii from 11 to nn and change its value to another value cc from 'a' to 'z';
  • choose two values c1c_1 and c2c_2 from 'a' to 'z' and replace the value of all parameters whose current value is c1c_1 with c2c_2;
  • check whether portals can be created at locations (l1,r1)(l_1, r_1) and (l2,r2)(l_2, r_2) (where l1⩽r1l_1 \leqslant r_1 and l2⩽r2l_2 \leqslant r_2). For this, the parameters at positions [l1,r1][l_1, r_1] must match elementwise the parameters at positions [l2,r2][l_2, r_2], that is, the following must hold:

{r1−l1=r2−l2pl1+i=pl2+ifor all 0⩽i⩽r1−l1\begin{cases} r_1 - l_1 = r_2 - l_2 \\ p_{l_1 + i} = p_{l_2 + i} & \text{for all } 0 \leqslant i \leqslant r_1 - l_1 \end{cases}

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 pp of length nn consisting of lowercase Latin letters, the initial values of the parameters (1⩽n⩽2⋅1051 \leqslant n \leqslant 2 \cdot 10^5).

The next line contains a single integer qq, the number of actions Morti performs (1⩽q⩽2⋅1051 \leqslant q \leqslant 2 \cdot 10^5).

Each of the next qq lines describes an action:

  • 1 ii cc: set the ii-th parameter to value cc (1⩽i⩽n1 \leqslant i \leqslant n; 'a' ⩽c⩽\leqslant c \leqslant 'z').
  • 2 c1c_1 c2c_2: replace every value equal to c1c_1 among all parameters with c2c_2 ('a' ⩽c1,c2⩽\leqslant c_1, c_2 \leqslant 'z').
  • 3 l1l_1 r1r_1 l2l_2 r2r_2: check whether portals can be created at locations (l1,r1)(l_1, r_1) and (l2,r2)(l_2, r_2) (1⩽l1,r1,l2,r2⩽n1 \leqslant l_1, r_1, l_2, r_2 \leqslant n; l1⩽r1l_1 \leqslant r_1; l2⩽r2l_2 \leqslant r_2).

Output

For each action of the third type, print YES on a separate line if Morti can perform it, and NO otherwise.

Examples2

  1. Example 1

    Input
    aaabc
    6
    3 1 2 2 3
    1 4 c
    2 c a
    3 1 4 2 5
    1 3 x
    3 1 4 2 5
    
    Expected output
    YES
    YES
    NO
    
  2. Example 2

    Input
    abracadabra
    7
    3 1 4 8 11
    1 7 r
    2 a c
    2 b c
    3 1 4 8 11
    3 1 4 5 8
    3 2 4 6 8
    
    Expected output
    YES
    YES
    YES
    YES