#abc280h. Ex - Substring Sort
Ex - Substring Sort
Score : points
问题描述
给定 个字符串 。令 $M = \displaystyle\sum_{i=1}^N \frac{|S_i|(|S_i|+1)}{2}$。
对于一个字符串 和整数 和 ,我们用 表示由第 个到第 个字符组成的子串。
考虑一个长度为 的三元组整数序列 $((K_1, L_1, R_1), (K_2, L_2, R_2), \ldots, (K_M, L_M, R_M))$,它满足以下条件:
- 这 个元素两两不同。
- 对于所有 ,有 且 。
- 对于所有 ,在字典序中满足 。
已知 个整数 ,它们介于 和 (包括两端点)之间。对于每个 ,找出 的可能实例。可以证明总存在满足条件的三元组序列。如果有多组满足条件的三元组,输出任意一组即可。此外,不同的 对应的满足条件的三元组序列不必相同。
什么是字典序?两个字符串 和 在字典序中满足 当且仅当以下任一条件成立:
- 并且 。
- 存在 ,使得对于所有 , 和 的第 个字符相同,且 的第 个字符在字母表上严格小于 的第 个字符。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given strings . Let $M = \displaystyle\sum_{i=1}^N \frac{|S_i|(|S_i|+1)}{2}$.
For a string and integers and , let us denote by the substring consisting of the -th through -th characters of .
A sequence of triples of integers $((K_1, L_1, R_1), (K_2, L_2, R_2), \ldots, (K_M, L_M, R_M))$ of length satisfies the following conditions:
- The elements are pairwise distinct.
- For all , it holds that and .
- For all , it holds that in the lexicographical order.
You are given integers between and , inclusive. For each , find a possible instance of . We can prove that there always exists a sequence of triples that satisfies the conditions. If multiple triples satisfy the conditions, print any of them. In addition, among different 's, the conforming sequence of triples does not have to be common.
What is the lexicographical order? Two strings and are said to be in the lexicographical order if and only if one of the following conditions is satisfied:
- and .
- There exists such that the -th characters of and are the same for all , and the -th character of is alphabetically strictly smaller than that of .
Constraints
- $\displaystyle\sum_{i=1}^N \lvert S_i\rvert\leq 10^5$
- $1 \leq x_1<x_2<\cdots<x_Q \leq \displaystyle\sum_{i=1}^N \frac{|S_i|(|S_i|+1)}{2}$
- are integers.
- is a string consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain an instance of conforming , separated by spaces. If multiple triples satisfy the conditions, print any of them.
Sample Input 1
2
abab
cab
2
5 14
Sample Output 1
1 3 4
2 1 1
We have . One possible sequence of triples that satisfies the conditions is $((1,1,1), (1,3,3), (2,2,2), (1,1,2), (1,3,4), (2,2,3), (1,1,3), (1,1,4), (1,2,2), (1,4,4), (2,3,3), (1,2,3), (1,2,4), (2,1,1), (2,1,2), (2,1,3))$. The corresponding sequence of for these in this order is (a
, a
, a
, ab
, ab
, ab
, aba
, abab
, b
, b
, b
, ba
, bab
, c
, ca
, cab
).
Note that the sequence satisfies the conditions even if we swap the -th element with the -th or -th one, so will also be accepted.
Sample Input 2
3
a
a
ba
2
1 2
Sample Output 2
1 1 1
1 1 1
We have . The sequence of triples that satisfies the conditions can be
or , for example.
Note that, for that you print, the conforming sequence whose -th element is does not have to be common among different ; in other words, there does not necessarily have to exist a sequence whose "-th element is for all ."
Sample Input 3
10
gxgpuamkx
szhkbpphykin
ezplvfja
mopodotkrj
rimlvumuar
nexcfyce
eurgvjyos
dhvuyfvt
nrdyluacvra
ggwnpnzij
6
74 268 310 380 455 489
Sample Output 3
3 1 2
4 4 5
4 3 7
9 6 6
6 6 6
2 2 12
update @ 2024/3/10 11:47:44