Sequence and Queries 34
Time limit2sMemory limit512 MB
Maintain two integer sequences under updates and range queries: for a suffix of a compute the longest match against b and how many suffixes achieve it, compare suffixes of b, and test whether a concatenation of two b-substrings is itself a substring of b.
- Level
Hard9 of 10
- Topics
- String matching, Segment tree, Sorting, String
- Solved
- No attempts yet
Problem
You are given two sequences and of positive integers with lengths and . Write a program that processes the queries below. All indices are 1-based.
1 y z: set , then print . (, )2 y z: print . ()3 y z: print . ()4 p q r s: printyesif the sequence is a contiguous subsequence of , andnootherwise. (, )
is the subsequence . The same definition applies to .
For two sequences and :
- is the length of the longest common prefix of and .
- is the pair of integers , where is the maximum of over all suffixes of , and is the number of suffixes that attain this maximum.
Input
The first line gives the length of . ()
The next line gives integers . ()
The next line gives the length of . ()
The next line gives integers . ()
The next line gives the number of queries . ()
Each of the following lines contains a query as described above.
Output
Print the result of each query in order, one per line.