Problem A
Helping Fill Bates
Input: Standard Input
Output: Standard Output
Time Limit: 10 Seconds
Everyone knows Fill Bates but I guess fewer people
know that he was famous in his high school days for a different reason. I just
put below the exact lines from one of his short biographies:
Before high-school graduation, Bates was
renowned for designing the class scheduling software that placed him in a class
full of girls. With his present success, those girls are probably mutilating
themselves for not buying in on an early investment.
Now you are
to help him with a completely different purpose. His company has initiated a
talent search program in QSA. It has 52 states (the original 50 states plus the
two recent troublesome additions Oraq and Malistan). The candidates from the 52 states are given a
state identity and a serial number (The serial number is unique). The state
identities for the 52 states are the 52 ASCII characters A..Z
and a..z. The talent search
process is a bit strange. At most 1 million candidates stand in a single line
according to the increasing order their serial number (Starting with 0 and then
1, 2, 3 …etc) with a placard showing only their state identity (After all who
wants to hire employees from Oraq and Malistan). Mr. Fill Gates then writes a sequence of
characters (Only alphabets). If candidates are found in that order of states
with increasing serial numbers (Some candidates may be skipped for this
purpose) then those candidates are taken. Other wise an appropriate message is
given.
Input
The input file contains only one set of
input. First line of the input file contains a string S containing only
alphabets. The length of this string is at most 1000000. The next line contains
an integer Q (0<Q<3501) which indicates the number of queries. Each of
the next Q lines contain one string SS of length less than 101. These strings
are the strings written by Fill Bates.
Output
For each query you should output one line. If
candidates are not found in the order written by Fill Bates then you should
output a string “Not matched” (Without the quotes), otherwise you should print
“Matched “ (Note that an space is printed after “Matched”) and then the serial
of the first candidate in the subsequence and the serial of the last candidate
of the subsequence. These two integers should be separated by a single space.
If there is more than one such subsequence then choose the one which has
smallest starting serial number. If there is a tie choose the one with the
smallest ending serial number.
Sample Input Output for Sample Input
aaaaaaaaaaaaaabbbbbbbbbdddddddddddccccccccccccc3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbcabcccNot matchedNot matchedMatched 0 36
Problemsetter: Shahriar Manzoor, Member of Elite Problemsetters' Panel
題目描述:
基本上可以想像成,現在有一排選單,根據優先順序先排好,
接著詢問挑的種類('a'-'z') 挑的順序可能比較特別。
盡可能挑排比較前面的來符合詢問要求的種類。
題目解法:
由於字串長度很長,盡可能先進行壓縮(run-length)。
然後挑的時候先進行一次壓縮,然後用二分詢尋找匹配的。
區間的方式按照字典順序,左區間越小越好,右區間越小越好。



