CF1037H.Security

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:512MB

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 ss consisting of lowercase English letters. Now they want to choose qq strings using the following steps, and you are to help them.

  1. A string xx consisting of lowercase English letters and integers ll and rr (1≤l≤r≤∣s∣1 \leq l \leq r \leq |s|) are chosen.
  2. Consider all non-empty distinct substrings of the slsl+1…srs_l s_{l + 1} \ldots s_r, that is all distinct strings sisi+1…sjs_i s_{i+1} \ldots s_{j} where l≤i≤j≤rl \le i \le j \le r. Among all of them choose all strings that are lexicographically greater than xx.
  3. If there are no such strings, you should print −1-1. Otherwise print the lexicographically smallest among them.

String aa is lexicographically less than string bb, if either aa is a prefix of bb and a≠ba \ne b, or there exists such a position ii (1≤i≤min(∣a∣,∣b∣)1 \le i \le min(|a|, |b|)), such that ai<bia_i \lt b_i and for all jj (1≤j<i1 \le j \lt i) aj=bja_j = b_j. Here ∣a∣|a| denotes the length of the string aa.

某个编程网站正在建立一种安全通信协议。出于安全考虑,他们希望选择若干个近乎随机的字符串。

最初,他们有一个由小写英文字母组成的字符串 ss。现在,他们希望按照以下步骤选择 qq 个字符串,而你需要协助完成这一任务。

  1. 选定一个由小写英文字母组成的字符串 xx,以及两个整数 ll 和 rr(满足 1≤l≤r≤∣s∣1 \leq l \leq r \leq |s|)。
  2. 考虑子串 slsl+1…srs_l s_{l + 1} \ldots s_r 的所有非空且互不相同的子串,即所有形如 sisi+1…sjs_i s_{i+1} \ldots s_{j} 的不同字符串,其中 l≤i≤j≤rl \le i \le j \le r。在这些子串中,选出所有字典序严格大于 xx 的字符串。
  3. 若不存在这样的字符串,则输出 −1-1;否则,输出其中字典序最小的那个字符串。

字符串 aa 的字典序小于字符串 bb,当且仅当满足以下任一条件:

  • aa 是 bb 的真前缀(即 aa 是 bb 的前缀且 a≠ba \ne b),或
  • 存在某个位置 ii(满足 1≤i≤min⁡(∣a∣,∣b∣)1 \le i \le \min(|a|, |b|)),使得 ai<bia_i \lt b_i,且对所有 jj(满足 1≤j<i1 \le j \lt i)均有 aj=bja_j = b_j。
    此处 ∣a∣|a| 表示字符串 aa 的长度。

输入格式

The first line of input contains a non-empty string ss (1≤∣s∣≤1051 \leq |s| \leq 10^{5}) consisting of lowercase English letters.

The second line contains an integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of strings to select.

Each of the next qq lines contains two integers ll, rr (1≤l≤r≤∣s∣1 \leq l \leq r \leq |s|) and a non-empty string xx consisting of lowercase English letters. The total length of strings xx for all queries does not exceed 2⋅1052 \cdot 10^{5}.

输入的第一行包含一个非空字符串 ss(1≤∣s∣≤1051 \leq |s| \leq 10^{5}),由小写英文字母组成。

第二行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5)—— 表示需要选择的字符串个数。

接下来的 qq 行中,每行包含两个整数 ll、rr(1≤l≤r≤∣s∣1 \leq l \leq r \leq |s|)以及一个非空字符串 xx(由小写英文字母组成)。所有查询中字符串 xx 的总长度不超过 2⋅1052 \cdot 10^{5}。

输出格式

Output qq lines, each of them should contain the desired string or −1-1, if there is no such string.

输出 qq 行,每行应包含所求的字符串;若不存在这样的字符串,则输出 −1-1。

输入输出样例

  • 输入#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 ss is "baa". The queries are as follows.

  1. We consider the substring s1s2s_1 s_2 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-1.
  2. We consider substring "aa". Among its substrings only "aa" is greater than the query string "a". So the answer is "aa".
  3. We consider substring "ba". Out of "b", "a" and "ba" only "ba" is greater than the query string "b", so the answer is "ba".
  4. We consider substring "aa". No substring of "aa" is greater than the query string "aa" so the answer is −1-1.
  5. 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".

考虑第一个例子。

字符串 ss 为 "baa"。查询如下:

  1. 我们考虑子串 s1s2s_1 s_2,即 "ba"。它的子串有 "b"、"a" 和 "ba";由于其中没有一个子串大于查询字符串 "ba",答案为 −1-1。
  2. 我们考虑子串 "aa"。在其所有子串中,只有 "aa" 大于查询字符串 "a",因此答案为 "aa"。
  3. 我们考虑子串 "ba"。在子串 "b"、"a" 和 "ba" 中,仅有 "ba" 大于查询字符串 "b",因此答案为 "ba"。
  4. 我们考虑子串 "aa"。"aa" 的任意子串均不大于查询字符串 "aa",因此答案为 −1-1。
  5. 我们考虑子串 "baa",其子串(包括但不限于)有 "ba" 和 "baa",二者均大于查询字符串 "b"。由于 "ba" 的字典序小于 "baa",因此答案为 "ba"。

输入解题思路,AI测评打分。不知道怎么写?

首页