A11989 | Security
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
1. A string $x$ consisting of lowercase English letters and integers $l$ and $r$ ( $1 \leq l \leq r \leq |s|$ ) are chosen.
2. Consider all non-empty distinct substrings of the $s_l s_{l + 1} \ldots s_r$ , that is all distinct strings $s_i s_{i+1} \ldots s_{j}$ where $l \le i \le j \le r$ . Among all of them choose all strings that are lexicographically greater than $x$ .
3. 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 \ne b$ , or there exists such a position $i$ ( $1 \le i \le min(|a|, |b|)$ ), such that $a_i < b_i$ and for all $j$ ( $1 \le j < i$ ) $a_j = b_j$ . Here $|a|$ denotes the length of the string $a$ .
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.
1. A string $x$ consisting of lowercase English letters and integers $l$ and $r$ ( $1 \leq l \leq r \leq |s|$ ) are chosen.
2. Consider all non-empty distinct substrings of the $s_l s_{l + 1} \ldots s_r$ , that is all distinct strings $s_i s_{i+1} \ldots s_{j}$ where $l \le i \le j \le r$ . Among all of them choose all strings that are lexicographically greater than $x$ .
3. 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 \ne b$ , or there exists such a position $i$ ( $1 \le i \le min(|a|, |b|)$ ), such that $a_i < b_i$ and for all $j$ ( $1 \le j < i$ ) $a_j = b_j$ . Here $|a|$ denotes the length of the string $a$ .
输入格式
The first line of input contains a non-empty string $s$ ( $1 \leq |s| \leq 10^{5}$ ) consisting of lowercase English letters.
The second line contains an integer $q$ ( $1 \le q \le 2 \cdot 10^5$ ) — the number of strings to select.
Each of the next $q$ lines contains two integers $l$ , $r$ ( $1 \leq l \leq r \leq |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 \cdot 10^{5}$ .
The second line contains an integer $q$ ( $1 \le q \le 2 \cdot 10^5$ ) — the number of strings to select.
Each of the next $q$ lines contains two integers $l$ , $r$ ( $1 \leq l \leq r \leq |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 \cdot 10^{5}$ .
输出格式
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.
1. We consider the substring $s_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$ .
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$ .
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".
The string $s$ is "baa". The queries are as follows.
1. We consider the substring $s_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$ .
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$ .
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".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted