B. Ilya and Queries
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < 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 < ri ≤ n).

Output

Print m integers — the answers to the queries in the order in which they are given in the input.

Sample test(s)
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 题解:一个字符串只有.或者#字符,给你一段区间[x,y],y>x,在这个区间里面统计s[i]=s[i+1]最多个数。
线性动态规划:转移方程

        if(a[i]==a[i-1])
    f[i]=f[i-1]+1;
    else f[i]=f[i-1];

 题目地址:http://codeforces.com/contest/313/problem/B

代码:

 #include<stdio.h>
#include<string.h> int i,j,n,x,y,m,
f[];
char a[]; int
main()
{
gets(a);
m=strlen(a);
f[]=;
for(i=;i<m;i++)
{
if(a[i]==a[i-])
f[i]=f[i-]+;
else f[i]=f[i-];
} scanf("%d",&n);
while(n--)
{
scanf("%d%d",&x,&y);
printf("%d\n",f[y-]-f[x-]);
} return ;
}

 

最新文章

  1. git 修改管理
  2. 奇怪的cab_xxxx_x文件
  3. Spring-事物传播行为
  4. extjs Combobox动态加载数据问题,mode:local 还是remote
  5. http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx
  6. 常见资源记录定义(Resource Record)
  7. android工程混淆和反编译
  8. Velocity引擎导致jvm内存外内存泄露
  9. tomcat最大线程数的设置(转)
  10. gitlab应用
  11. SLAM入门之视觉里程计(5):单应矩阵
  12. MYSQL数据库学习十二 使用MySQL运算符
  13. HDU 1724 Ellipse
  14. (干货)微信小程序之转发好友
  15. scala查询dataFrame结构
  16. uva 10123 - No Tipping dp 记忆化搜索
  17. 微信网页授权获取用户openid及用户信息
  18. python selenium-webdriver 等待时间(七)
  19. 【Convex Optimization (by Boyd) 学习笔记】Chapter 1 - Mathematical Optimization
  20. python 函数定义及调用

热门文章

  1. android4.0默认界面旋转180
  2. 怎样制作百度recovery【转】
  3. Oracle set autotrace 时提示:Cannot find the Session Identifier. Check PLUSTRACE role is enabled
  4. LeetCode_Climbing Stairs
  5. How can I let the compiled script depend on something dynamic
  6. 【转】Windows 7/8/8.1 硬盘安装法实现 ubuntu 14.04 双系统
  7. amcharts报表制作
  8. DHTML【8】--CSS
  9. PHP设计模式笔记七:观察者模式 -- Rango韩老师 http://www.imooc.com/learn/236
  10. Codeforces 468B Two Sets 并查集