#P10995. 【MX-J3-T2】 Substring
【MX-J3-T2】 Substring
Background
Original problem link: https://oier.team/problems/J3C.
Problem Description
You have a sequence , where each of appears exactly once.
When you choose any pair and write in a row, you obtain a substring of , denoted as . Here, is called the left endpoint and is called the right endpoint.
You need to sort all substrings of in lexicographical order from small to large. However, to avoid an excessively large output, I will give queries. In each query, a is given, and you need to find the left and right endpoints of the -th smallest substring in lexicographical order.
If you do not know what lexicographical order is, see here:
For two sequences , we say is lexicographically smaller than (denoted ) if and only if there exists a natural number such that the first numbers of and are the same, and .
In particular, if is a prefix of and , then is also considered lexicographically smaller than .
For example:
- (when ).
- (when ).
- ( is a prefix of ).
Input Format
The first line contains two positive integers , representing the length of the sequence and the number of queries.
The second line contains positive integers , representing the sequence.
Then follow lines, each containing one positive integer , representing the required rank of the substring.
Output Format
For each query, output one line with two integers , indicating that the -th smallest substring in lexicographical order is .
3 6
3 1 2
1
2
3
4
5
6
2 2
2 3
3 3
1 1
1 2
1 3
50 25
42 22 27 8 44 11 14 31 37 10 48 15 12 40 13 4 25 9 19 5 2 18 6 1 32 3 38 33 43 34 46 47 23 35 21 20 45 39 50 7 36 17 24 29 16 30 49 26 28 41
1178
991
755
1094
689
132
671
635
421
659
448
334
327
213
1206
453
1160
583
388
781
150
692
23
1162
62
37 48
27 44
3 28
1 46
43 47
20 34
33 37
2 19
15 44
2 43
7 27
6 31
6 24
4 29
32 37
7 32
5 44
19 47
13 47
44 45
23 24
43 50
24 46
5 46
26 30
Hint
[Sample Explanation #1]
The sequence has substrings in total. After sorting from small to large, the result is: .
[Constraints]
| Test Point ID | Special Property | ||
|---|---|---|---|
For all testdata, it is guaranteed that , , each of appears exactly once in , and all inputs are integers.
Translated by ChatGPT 5