CF1037H.Security
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Some programming website is establishing a secure communication protocol. For security reasons, they want to choose several more or less random strings.
Initially, they have a string s consisting of lowercase English letters. Now they want to choose q strings using the following steps, and you are to help them.
- A string x consisting of lowercase English letters and integers l and r ( 1≤l≤r≤∣s∣ ) are chosen.
- Consider all non-empty distinct substrings of the slsl+1…sr , that is all distinct strings sisi+1…sj where l≤i≤j≤r . Among all of them choose all strings that are lexicographically greater than x .
- If there are no such strings, you should print −1 . Otherwise print the lexicographically smallest among them.
String a is lexicographically less than string b , if either a is a prefix of b and a=b , or there exists such a position i ( 1≤i≤min(∣a∣,∣b∣) ), such that ai<bi and for all j ( 1≤j<i ) aj=bj . Here ∣a∣ denotes the length of the string a .
输入格式
The first line of input contains a non-empty string s ( 1≤∣s∣≤105 ) consisting of lowercase English letters.
The second line contains an integer q ( 1≤q≤2⋅105 ) — the number of strings to select.
Each of the next q lines contains two integers l , r ( 1≤l≤r≤∣s∣ ) and a non-empty string x consisting of lowercase English letters. The total length of strings x for all queries does not exceed 2⋅105 .
输出格式
Output q lines, each of them should contain the desired string or −1 , if there is no such string.
输入输出样例
输入#1
baa 5 1 2 ba 2 3 a 1 2 b 2 3 aa 1 3 b
输出#1
-1 aa ba -1 ba
输入#2
bacb 4 1 2 ba 2 3 ac 1 3 ac 3 4 c
输出#2
-1 c b cb
输入#3
bba 1 1 1 b
输出#3
-1
说明/提示
Consider the first example.
The string s is "baa". The queries are as follows.
- We consider the substring s1s2 that is "ba". It has substrings "b", "a" and "ba", since none of them is greater than the query string "ba", the answer is −1 .
- We consider substring "aa". Among its substrings only "aa" is greater than the query string "a". So the answer is "aa".
- We consider substring "ba". Out of "b", "a" and "ba" only "ba" is greater than the query string "b", so the answer is "ba".
- We consider substring "aa". No substring of "aa" is greater than the query string "aa" so the answer is −1 .
- We consider substring "baa" and it has (among others) substrings "ba", "baa" which are greater than the query string "b". Since "ba" is lexicographically smaller than "baa", the answer is "ba".
输入解题思路,AI测评打分。不知道怎么写?