递推 Codeforces Round #186 (Div. 2) B. Ilya and Queries
/*
递推:用cnt记录前缀值,查询区间时,两个区间相减
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
char s[MAXN];
int cnt[MAXN]; int main(void) //Codeforces Round #186 (Div. 2) B. Ilya and Queries
{
scanf ("%s", s + );
int len = strlen (s + ); memset (cnt, , sizeof (cnt));
for (int i=; i<len; ++i)
{
cnt[i] = cnt[i-] + (s[i] == s[i+] ? : );
// printf ("%d ", cnt[i]);
}
cnt[len] = cnt[len-]; int m; scanf ("%d", &m);
while (m--)
{
int l, r; scanf ("%d%d", &l, &r);
printf ("%d\n", cnt[r-] - cnt[l-]);
} return ;
}
递推 Codeforces Round #186 (Div. 2) B. Ilya and Queries的更多相关文章
- [Codeforces Round #186 (Div. 2)] B. Ilya and Queries
B. Ilya and Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- [Codeforces Round #186 (Div. 2)] A. Ilya and Bank Account
A. Ilya and Bank Account time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- Codeforces Round #186 (Div. 2).D
纠结的一道dp. 状态转移方程还是比较好想的,优化比较纠结 D. Ilya and Roads time limit per test 3 seconds memory limit per test ...
- Codeforces Round #186 (Div. 2)
A. Ilya and Bank Account 模拟. B. Ilya and Queries 前缀和. C. Ilya and Matrix 考虑每个元素的贡献. 边长为\(2^n\)时,贡献为最 ...
- Codeforces Round #311 (Div. 2) A. Ilya and Diplomas 水题
A. Ilya and Diplomas Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/ ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题
C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree
地址:http://codeforces.com/contest/842/problem/C 题目: C. Ilya And The Tree time limit per test 2 second ...
随机推荐
- android framework navigationbar自定义
需要实现的目标:在navigationbar上显示录像预览,并且点击按钮可以显示/隐藏NavigationBar 参考文章: http://blog.csdn.net/yanlai20/article ...
- POJ 3518 (后缀自动机)
POJ 3518 Boring Problem : 给一个串S,询问串S有多个子串出现至少两次且位置不重叠. Solution : 对S串建立后缀自动机,再建立后缀树,dfs一遍统计处每个结点的子树中 ...
- msp430入门学习21
msp430的USART的SPI模式 msp430入门学习
- HDU 5642 King's Order【数位dp】
题目链接: http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=677&pid=1003 题意: 求长度为n的序列 ...
- html自动换行
对于div,p等块级元素 正常文字的换行(亚洲文字和非亚洲文字)元素拥有默认的white-space:normal,当定义的宽度之后自动换行html css 1.(IE浏览器)连续的英文字符和阿拉伯数 ...
- http://www.cnblogs.com/sprinkle/
http://www.cnblogs.com/sprinkle/ http://www.cnblogs.com/sprinkle/
- Vmware worksiation中使用ISO
Vmware技巧: 用ISO安装系统,需要添加2个CD设备. IDE 1 中选择 autoinst.iso IDE 2 中选择 “要安装的系统”.iso 简单讲:Vmware模拟机上需要模拟两次i ...
- [php learn] php 从头開始学习1
前言:大概在2006年的时候,学习过一段时间的php.而且当时做了一个下载的站点,后来因为读研究生阶段用的是java.j2ee相关,所以php就搁浅掉了,php这些年也发生了非常大的变化,最大一个变化 ...
- Ganglia API安装与使用
Ganglia监控本身没有提供API可供外部程序调用,只是依据ganglia监控的原理,能够通过分析gmetad的port的xml来直接获取metrics. Guardian已经在Github上公布了 ...
- 【code】flex_进度条样式
近期打算吧硬盘中的资料记录在博客中,实用的就当是个分享,无用的就当是个备份,还望大家不要见怪. 一共4个文件: JinDuTiaoItem.mxml: <?xml version="1 ...