Alien Molecule
Time limit3sMemory limit1024 MB
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.
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 . It describes the original form of the alien molecule.
The second line contains the number of strings that Team 41 will check.
The next lines contain the strings . Note that may be longer than .
The next line contains the number of queries . The next lines contain the following queries.
- : All characters from the th to the th character of the alien molecule change to the character .
- : Consider the string formed by the th to the th characters of the alien molecule, that is, the substring . Print 1 if it matches one of , 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
- all consist of uppercase English letters. ()
Hint
For a string of length and two integers and with , is the string that contains the characters of from the th to the th position in order. Such strings are called substrings of .
For example, if is ABCDABA, then is ABCDA and is CDABA. So ABCDA and CDABA are substrings of ABCDABA. However, AAAA is not a substring of ABCDABA.
(Source: 가장 긴 공통 괄호 문자열, KOI 2021)