eolymp
bolt
Try our new interface for solving problems
Məsələlər

Jewel Magic

Jewel Magic

I am a magician. I have a string of emeralds and pearls. I may insert new jewels in the string, or remove old ones. I may even reverse a consecutive part of the string. At anytime, if you point to two jewels and ask me, what is the length of the longest common prefix (LCP) of jewel strings starting from these two jewels, I can answer your question instantly. Can you do better than me? Formally, you'll be given a string of \textbf{0} and \textbf{1}. You're to deal with four kinds of operations (in the following descriptions, L denotes the current length of the string, and jewel positions are number \textbf{1} to \textbf{L} numbered from left to right): \InputFile There will be several test cases. The first line of each test case contains an integer \textbf{n} and \textbf{m} (\textbf{1} ≤ \textbf{n}, \textbf{m} ≤ \textbf{200,000}), where \textbf{n} is the number of pearls initially, \textbf{m} is the number of operations. The next line contains a \textbf{01} string of length \textbf{n}. Each of the next \textbf{m} lines contains an operation. The input is terminated by end-of-file (\textbf{EOF}). The size of input file does not exceed \textbf{5} MB. \OutputFile For each type-\textbf{4} operation, output the answer. \Note String after operation \textbf{1 0 1}: \textbf{1000100001100 } String after operation \textbf{3 7 10}: \textbf{1000101000100 } String after operation \textbf{2 9}: \textbf{100010100100}
Zaman məhdudiyyəti 5 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
12 9
000100001100
1 0 1
4 2 6
3 7 10
4 1 7
2 9
4 3 11
4 1 9
4 1 7
4 2 3
Çıxış verilənləri #1
3
6
2
0
3
2