No.1018 suffixsuffixsuffix
Problem Statement
You are given a string $S$ of length $N$, a positive integer $M$, and a sequence $K_1,\ldots,K_Q$ of length $Q$.
Let $T$ be the string obtained by repeating the string $S$ $M$ times. When the suffixes $T_1, T_2, \ldots, T_{NM}$ of $T$ are sorted in lexicographical order, find the $K_1,\ldots,K_Q$-th suffixes.
Here, the suffix $T_i$ of $T$ is the substring of $T$ from the $i$-th character to the end.
Input
$N\ M\ Q$ $S$ $K_1\ K_2\ \ldots \ K_Q$
- $N$ is a positive integer satisfying $1\leqq N\leqq 10^5$.
- $M$ is a positive integer satisfying $1\leqq M\leqq 10^9$.
- $Q$ is a positive integer satisfying $1\leqq Q\leqq \min(NM, 10^5)$.
- $S$ is a string of length $N$ consisting of lowercase English letters.
- $K_i$ are positive integers satisfying $1\leqq K_1 < K_2 < \cdots < K_Q \leqq NM$.
Output
For each $i$, find $n_i$ such that the $K_i$-th suffix is $T_{n_i}$, and print them separated by spaces.
Print a newline at the end.
Sample
Sample 1
Input
4 2 8 puyo 1 2 3 4 5 6 7 8
Output
8 4 5 1 6 2 7 3
$T = \text{puyopuyo}$. Sorting the suffixes in lexicographical order gives the following order.
- $T_8 = \text{o}$
- $T_4 = \text{opuyo}$
- $T_5 = \text{puyo}$
- $T_1 = \text{puyopuyo}$
- $T_6 = \text{uyo}$
- $T_2 = \text{uyopuyo}$
- $T_7 = \text{yo}$
- $T_3 = \text{yopuyo}$
Sample 2
Input
5 10 4 ahaha 10 20 30 40
Output
5 3 1 4
Sample 3
Input
5 10 4 ihihi 10 20 30 40
Output
7 4 11 8
Sample 4
Input
26 1000000000 1 abcdefghijklmnopqrstuvwxyz 26000000000
Output
26
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
maspy
beet