Rank Among the Suffixes
Sort all suffixes of S lexicographically. Answer Q queries: what is the rank (1-based) of the suffix that starts at position i?
Input: the first line has S; the second line has Q; each of the next Q lines has a start position i.
Output: one line per query with the suffix's rank.
Constraints:
- 1 ≤ |S| ≤ 105
- 1 ≤ Q ≤ 105
Sample Tests
Input 1
banana 2 1 2
Output 1
4 3
Input 2
ab 1 2
Output 2
2
Discussion (opens after you solve — no spoilers before)
No comments yet.