博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 313B - Ilya and Queries(水题)
阅读量:6175 次
发布时间:2019-06-21

本文共 1811 字,大约阅读时间需要 6 分钟。

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), thatsi = 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.

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 题意:找出给定区间内相邻字符的个数。水题,不多解释。
#include
#include
using namespace std;int main(){ string s; while (cin >> s) { int n, a[100005] = { 0 }; for (int i = 1; i < s.length(); i++) { if (s[i-1] == s[i]) a[i] = a[i - 1] + 1; else a[i] = a[i - 1]; } cin >> n; while (n--) { int x, y; cin >> x >> y; cout << a[y - 1] - a[x - 1] << endl;; } } return 0;}

 

 

转载于:https://www.cnblogs.com/orion7/p/7009048.html

你可能感兴趣的文章
Linux安装jdk
查看>>
经验积累:SoapUI的使用相关--动态取得的Soap Message内容,动态匹配应答
查看>>
SMG协同办公平台规划与实践
查看>>
短视频客户端SDK设计与实现
查看>>
Sublime Text3—设置快捷键打开浏览器----转载
查看>>
hibernate笔记--基于主键的单(双)向的一对一映射关系
查看>>
Vue 动态控制某个组件的缓存
查看>>
Java并发编程笔记之SimpleDateFormat源码分析
查看>>
华硕举行“游戏新浸界”品鉴会,主打新品全面拥抱VR
查看>>
eclipse无法识别javax.servlet.*的问题
查看>>
Linux中通过/dev/mem操控物理地址
查看>>
微软开源用于 Azure 数据压缩的算法、硬件和源码
查看>>
深度:那些梦碎乐视的造车高人!
查看>>
有关UIView、subview的几个基础知识点-IOS开发 (实例)
查看>>
SpaceX新型发动机发生爆炸,但称不会对发射计划造成影响
查看>>
sql server top 10 IO性能查询
查看>>
Java学习笔记--线程和多线程线程池(简单理解)
查看>>
BigMemory系列文章--3. Ehcache存储层级(tier)
查看>>
百度副总裁说,阿波罗计划就是个平台,为自动驾驶提供一个生态
查看>>
tomcat 热部署 总是building workspace
查看>>