F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Dynamic Lover

Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1593    Accepted Submission(s): 446


Problem Description
As a famous person with universal love, changing girlfriend too often makes me harassment because I can't keep their name in mind timely. To remember who is my lover now, I buy a magic password-box from a wizard.
As a faithful atheist, I do not believe that it is caused by magic power. By doing a deep research, I find that all "magic" factors are just because a small software inside the box. Because the software only uses some simple data structure, it has a dissatisfied complexity.
Now I shortly introduce the principle of the software.
We will support a string with dynamic length and three kinds of operations on it. You can assume that we will always have an initial string.
*1. You will receive a short string, and you should connect it after the original string to make the new string.
*2. You will receive an integer len, and you should answer the query: for each index i (1 <= i <= LEN(nowString)), we will get a sub-string from i to i + len - 1 (if i + len - 1 > LEN(nowString), you should make the suffix from index i as its sub-string). You should output the index i whose sub-string has minimum lexicographic.
*3. You will receive an integer len. You should delete the suffix whose length is len from the string now and get a new string.
As a former ACMer, I want to make a new production with better execution speed. But I am not good at data structure, so I need your help.
 

Input
There are multiple test cases.
The first line contains a string as the initial string.
The next line contains an integer m (1 <= m <= 100,000) indicating the number of the operations.
Each of the next m lines begins with an integer k (1 <= k <= 3) indicating the kind of operation. If k = 1, it is followed by a short non-empty string, otherwise it is followed by an integer len.
We guarantee that the total length of the initial string and all short strings are not more than 100,000. And for each query, the len is not more than 1000 and the total sum of len is not more than 100,000.
All characters in the input are lower case.
 

Output
For each test case, you should output several lines.
For each query, you should output a line indicating the index i whose sub-string has minimum lexicographic. If more answers exist, output the minimal index.
 

Sample Input
aacbab 5 2 2 1 aaa 2 3 3 2 2 3
 

Sample Output
1 9 7
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-18 21:01:54, Gzip enabled