6082: 伊利亚和查询

内存限制:256 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:5 通过:3

题目描述


狮子伊利亚想帮助他所有的朋友通过考试。他们需要解决以下问题才能通过 IT 考试。
你有字符串 s=s1s2...sn(n 是字符串的长度),仅由字符 “.” 和 “#” 以及 m 查询组成。每个查询由一对整数 li,ri (1≤li<ri≤n) 描述。查询 li,ri 的答案是此类整数 i (li≤i<ri) 的数量,即 si=si+1。
狮子伊利亚想帮助他的朋友,但有人可以帮助他吗?帮助伊利亚,解决问题。

Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string s=s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li,ri (1≤li<rin). The answer to the query li,ri is the number of such integers i (lii<ri), that si=si+1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
Input
The first line contains string s of length n (2≤n≤105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer m (1≤m≤105) − the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li,ri (1≤li<rin).
Output
Print m integers − the answers to the queries in the order in which they are given in the input.
Examples
Input
......
4
3 4
2 3
1 6
2 6
Output
1
1
5
4
Input
#..###
5
1 3
5 6
1 5
3 6
3 4
Output
1
1
2
2
0

输入格式

第一行包含长度为 n (2≤n≤10^5) 的字符串 s。保证给定的字符串仅由字符“.”和“#”组成。
下一行包含整数 m (1≤m≤10^5) - 查询数。接下来的 m 行中的每一行都包含相应查询的说明。第 i 行包含整数 li,ri (1≤li<ri≤n)。

输出格式

打印 m 个整数 - 查询的答案,按它们在输入中给出的顺序排列。
例子
输入
......
4
3 4
2 3
1 6
2 6
输出
1
1
5
4
输入
#..###
5
1 3
5 6
1 5
3 6
3 4
输出
1
1
2
2
0

输入样例 复制

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

输出样例 复制

1
1
5
4