RAM
Time limit2sMemory limit512 MB
Process files one by one; after each, count how many times a given letter appears in the last K characters seen so far.
- Level
Medium6 of 10
- Topics
- Array, Simulation, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Hackers broke into Mirko's computer through the Shellshock vulnerability and raised the system voltage, destroying almost all of its RAM except the last 2MB. Mirko's computer has exactly 26 hard disks, labeled with the uppercase English letters A to Z. Fortunately, Mirko has a huge log of hard disk accesses. The log is a string of hard disk labels in the order the disks were accessed.
Mirko analyzed the attack as follows:
- He split the log into smaller files that fit in RAM. Each file is a string of uppercase English letters, and concatenating the files in order gives the whole log.
- He loaded the files one after another. Right after loading file , he counted how many times hard disk was accessed among the last accesses of the log from its beginning up to and including file .
Write a program that answers all of Mirko's queries.
Input
The first line contains the number of files ().
The next lines are divided into groups of two lines. The -th group is:
- The first line contains a string of uppercase English letters ().
- The second line contains an uppercase English letter , the label of a hard disk, and the number of accesses , separated by a space ().
The total length of all files, , is at most .
Output
Print lines with the answers to Mirko's queries in order. Line contains the exact number of characters equal to among the last characters of the concatenation of through .