#CT00000052. Tín hiệu nén (Compressed Signal)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Tín hiệu nén (Compressed Signal)
Compressed Signal
Version: Phuoc Hung OJ Extended
Problem Statement
A device stores an original signal consisting only of lowercase English letters from a to z. To save space, the signal is represented as a sequence of consecutive groups. Each group contains a letter repeated times and is encoded as the positive decimal integer immediately followed by .
Concatenating all encoded groups in their original order produces the compressed string . Repetition counts have no leading zeros. Adjacent groups may contain the same letter; they are not required to be merged.
For example, 3a2b4a represents aaabbaaaa: three a letters, then two b letters, then four a letters. Positions in the decoded signal are numbered from through its total length.
You are given queries. Each query specifies a position in the original signal. Determine the letter at exactly position , without having to output the entire decoded signal.
Input
- The first line contains the compressed string with no spaces. It consists of one or more valid groups, each encoded as a positive repetition count followed by a lowercase English letter.
- The second line contains the positive integer , the number of queries.
- Each of the next lines contains a positive integer , the queried position in the decoded signal. All queried positions are valid.
Output
Print exactly lines in query order. Line contains one lowercase English letter: the letter at position of the decoded signal.
Subtasks
The following general constraints apply to all subtasks: ; ; each group count is in ; the decoded length is at most ; the decoded length.
- Subtask 1 (30%): The decoded length is at most .
- Subtask 2 (30%): Every group count is at most .
- Subtask 3 (40%): No additional restrictions beyond the general constraints.
Examples
Example 1
Input
3a2b4a
6
1
3
4
5
6
9
Output
a
a
b
b
a
a
Explanation
The groups in 3a2b4a occupy the following positions: through contain a, through contain b, and through contain a. The queried positions therefore produce a, a, b, b, a, a, in that order.
Example 2
Input
12z1a
3
1
12
13
Output
z
z
a
Explanation
Group 12z occupies positions through , all containing z. Group 1a occupies position . Therefore positions , , and contain z, z, and a, respectively.
Example 3
Input
1a1a1b
3
1
2
3
Output
a
a
b
Explanation
The three groups 1a, 1a, and 1b have lengths . The first two groups are valid even though they share the same letter, and the decoded signal is aab. Positions , , and therefore contain a, a, and b.
Liên quan
Trong các cuộc thi sau: