#K3876. Count Character in Substring

    ID: 26270 Type: Default 1000ms 256MiB

Count Character in Substring

Count Character in Substring

You are given a string ( s ) and ( Q ) queries. Each query is represented by two integers ( l ) and ( r ) and a character ( c ). For each query, your task is to determine the number of times the character ( c ) appears in the substring of ( s ) from index ( l ) to ( r ) (inclusive).

Formally, for each query, compute [ \text{count} = #{ i \mid l \le i \le r \text{ and } s[i] = c}]
where the string index is 0-indexed.

inputFormat

The input is given via standard input (stdin) and has the following format:

1. The first line contains the string ( s ).
2. The second line contains an integer ( Q ), the number of queries.
3. Each of the next ( Q ) lines contains two integers ( l ), ( r ) and a character ( c ), separated by spaces.

outputFormat

For each query, output a single integer on a new line that represents the number of times the character ( c ) occurs in the substring ( s[l...r] ). The output should be printed to standard output (stdout).## sample

abracadabra
1
1 3 a
1

</p>