eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Automatic Trading

Automatic Trading

A brokerage firm is interested in detecting automatic trading. They believe that a particular algorithm repeats itself; that is, it makes the same sequence of trades at a later time. The firm has identified a set of \textbf{26} key stocks that they believe are likely to be traded in concert, and they’ve encoded a series of trades as a string of letters: the letter itself indicates the stock, upper case indicates a \textit{buy}, lower case indicates a \textit{sell}. They want you to write a program to determine, for any two starting points, the longest sequence of identical trades from those two starting points, starting from and including those starting points as the first trade in the sequence. \InputFile There will be several test cases in the input. Each test case will start with a string \textbf{s} on the first line, consisting solely of upper case and lower case letters (\textbf{1} ≤ \textbf{length(s)} ≤ \textbf{100000}). On the next line will be an integer \textbf{q} (\textbf{1} ≤ \textbf{q} ≤ \textbf{100000}), indicating the number of queries. The following \textbf{q} lines each describe a query with two integers, \textbf{i} and \textbf{j} (\textbf{0} ≤ \textbf{i} < \textbf{j} < \textbf{length(s)}), which represent two zero-based positions in the string. The input will end with a line containing only an asterisk ('\textbf{*}'). \OutputFile For each query, output a single integer, indicating the length of the longest sequence of trades starting at \textbf{i} which is identical to the sequence of trades starting at \textbf{j}. Output no spaces. Do not print any blank lines between lines of output.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Источник The University of Chicago Invitational Programming Contest 2013, March 29-31, 2013