#C1104. Count Character Occurrences in Substrings

    ID: 40312 Type: Default 1000ms 256MiB

Count Character Occurrences in Substrings

Count Character Occurrences in Substrings

You are given a string \(s\) and a number of queries \(q\). Each query consists of a character \(C\) and two integers \(L\) and \(R\). For every query, your task is to determine the number of times the character \(C\) appears in the substring of \(s\) from index \(L\) to index \(R\) (inclusive).

Note: The indices are 0-indexed. That is, the first character of the string is at index 0.

For example, if \(s = \texttt{abcdefg}\) and the query is \(('a', 0, 3)\), then you need to count the occurrences of \(\texttt{'a'}\) in the substring \(\texttt{s[0..3]} = \texttt{'abcd'}\), which yields a count of 1.

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  1. The first line contains the string \(s\).
  2. The second line contains an integer \(q\), the number of queries.
  3. Each of the following \(q\) lines contains a character \(C\) and two integers \(L\) and \(R\) separated by spaces.

outputFormat

For each query, output a single line to standard output (stdout) with the count of the character \(C\) in the substring of \(s\) from index \(L\) to \(R\) (inclusive).

## sample
abcdefg
3
a 0 3
d 0 6
g 5 6
1

1 1

</p>