Under construction

Still being built. Things may change

Alien Molecule

Time limit3sMemory limit1024 MB

Summary
Given a string S with range-overwrite updates, the task answers whether each substring S[l..r] equals one of N given patterns.
Level

Medium6 of 10

Topics
Segment tree, String matching, Hash map
Solved
No attempts yet

Problem

Team 41 chose a very ambitious topic for their R&E project: retrieving genetic information from alien life. It sounds absurd and impossible, but Team 41 extracted an alien molecule within a single semester! The molecule was a line of regular genetic units bonded side by side, much like the base sequence of DNA. They had captured strong evidence that alien life really exists.

To analyze the alien molecule, Team 41 gave each molecule its own string. The molecule was built from combinations of 26 kinds of genetic units. Team 41 mapped the units to the letters A to Z, so a molecule was written as a string such as ABRTTWYS⋯\cdots.

Then a serious problem appeared. When the alien molecule meets Earth's atmosphere, it changes severely. Over time the molecules became contaminated, and after a long while they had a structure completely different from the one first sampled. Team 41 did not want to lose this valuable data, so they used the following method.

Team 41 observed that alien molecules, like DNA, have complementary pairs of molecules. Based on this, they could determine whether a specific molecular sequence exists in an alien molecule. Using that ability, Team 41 wanted to find which specific molecular sequences exist at a given time and use them to roughly reconstruct the original form.

You are a god. You know how this DNA will change in the future. Use that knowledge to determine whether Team 41 can observe specific molecular sequences at a given time!

Input

The first line contains the string SS. It describes the original form of the alien molecule.

The second line contains the number NN of strings that Team 41 will check.

The next NN lines contain the NN strings T1,T2,⋯ ,TNT_1, T_2, \cdots, T_N. Note that TiT_i may be longer than SS.

The next line contains the number of queries QQ. The next QQ lines contain the following queries.

  • 11 ll rr cc: All characters from the llth to the rrth character of the alien molecule change to the character cc.
  • 22 ll rr: Consider the string formed by the llth to the rrth characters of the alien molecule, that is, the substring S[l⋯r]S[l \cdots r]. Print 1 if it matches one of T1,T2,⋯ ,TNT_1, T_2, \cdots, T_N, and 0 otherwise.

Output

Print the answer to each query of type 2 on its own line.

There is at least one query of type 2.

Constraints

  • 1≤N≤1,000,0001\leq N\leq 1,000,000
  • 1≤Q,∣S∣≤250,0001\leq Q,|S|\leq 250,000
  • 1≤∣Ti∣≤1,000,0001\leq|T_i|\leq 1,000,000
  • 1≤∑i=1N∣Ti∣≤1,000,0001\leq\displaystyle\sum_{i=1}^{N}|T_i|\leq 1,000,000
  • 1≤l≤r≤∣S∣1\leq l\leq r\leq |S|
  • S,Ti,cS, T_i, c all consist of uppercase English letters. (1≤i≤N1\leq i\leq N)

Hint

For a string SS of length ll and two integers ii and jj with 1≤i≤j≤l1 \leq i \leq j \leq l, S[i⋯j]S[i \cdots j] is the string that contains the characters of SS from the iith to the jjth position in order. Such strings are called substrings of SS.

For example, if SS is ABCDABA, then S[1⋯5]S[1 \cdots 5] is ABCDA and S[3⋯7]S[3 \cdots 7] is CDABA. So ABCDA and CDABA are substrings of ABCDABA. However, AAAA is not a substring of ABCDABA.

(Source: 가장 긴 공통 괄호 문자열, KOI 2021)

Examples1

  1. Example 1

    Input
    ABABABAB
    5
    AB
    ABCD
    EE
    BCDE
    BABA
    10
    2 1 2
    2 2 3
    1 3 3 B
    2 2 5
    1 7 8 E
    2 7 8
    1 3 5 C
    1 4 8 D
    2 1 4
    2 2 5
    
    Expected output
    1
    0
    0
    1
    1
    0