More Queries

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

jsumabat has been given N queries from liwi to answer. The queries are as follows:

You are given a string, S, with size M, consisting of characters # and . You are also given N, the number of queries.

For each query, you are given two integers, l_i and r_i (1 \le l_i < r_i \le M).

The solution to each query l_i r_i is the number of such integers i (l_i \le i < r_i), that S_i = S_{i+1}.

Input Specification

The first line contains a string S of length M (2 \le M \le 10^5). It is guaranteed that the string will only contain the characters # and .

The second line of input will contain N (1 \le N \le 10^5), the number of queries you are to process.

The next N lines will contain 2 integers, l_i and r_i (1 \le l_i < r_i \le M).

Output Specification

Print N integers, the answers to the queries in the order given in the input, each on a separate line.

Sample Input 1

......
4
3 4
2 3
1 6
2 6

Sample Output 1

1
1
5
4

Sample Input 2

#..###
5
1 3
5 6
1 5
3 6
3 4

Sample Output 2

1
1
2
2
0

Comments

There are no comments at the moment.