递推 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 ...
随机推荐
- 自定义日志工具LogUtil
package com.pingyijinren.test; import android.util.Log; /** * Created by Administrator on 2016/5/20 ...
- [bzoj5101][POI2018]Powódź_并查集
Powódź bzoj-5101 POI-2018 题目大意:在地面上有一个水箱,它的俯视图被划分成了$n$行$m$列个方格,相邻两个方格之间有一堵厚度可以忽略不计的墙,水箱与外界之间有一堵高度无穷大 ...
- BNU2017校赛
A(模拟) 题意:求一个特殊图的最大流 分析:画画图发现就是for循环扫一遍 B(LCA) 题意:有n个点组成的树,有q个询问,每个询问(A,B,C),学生从B点走最短路径走到C点,再从C点走到根节点 ...
- Spring Cloud(6):Zuul的基本使用
网关:API Gateway 系统对外唯一入口,介于客户端和服务端之间,处理非业务功能 提供路由请求,鉴权,监控,缓存,限流等功能 简单理解:小区门卫,防止非法人员入内,居民也可以问路 实际理解:假设 ...
- 18.9.23 PION模拟赛
U32670 小凯的数字 题目背景 NOIP2018 原创模拟题T1 NOIP DAY1 T1 or DAY 2 T1 难度 是否发现与NOIP2017 DAY1 T1 有异曲同工之妙 说明:#10, ...
- Ubuntu 16.04安装Markdown编辑器MarkMyWords
继上一篇文章http://www.cnblogs.com/EasonJim/p/7119345.html中使用Sublime Text 3进行Markdown的编辑,总觉得操作上比较繁琐,现在推荐使用 ...
- webpack 输出多个文件
http://react-china.org/t/webpack/1870/2 webpack 文章 entry = { "button": "demo/button/i ...
- MapReduce WordCount Combiner程序
MapReduce WordCount Combiner程序 注意使用Combiner之后的累加情况是不同的: pom.xml <project xmlns="http://maven ...
- day1--大数据概念,hadoop介绍,hdfs整体运行机制
1.什么是大数据 基本概念 在互联网技术发展到现今阶段,大量日常.工作等事务产生的数据都已经信息化,人类产生的数据量相比以前有了爆炸式的增长,以前的传统的数据处理技术已经无法胜任,需求催生技术,一套用 ...
- i18n国际化的例子
这个可以点击菜单进行中英文切换,每次切换就可以改变sessionStorage.languge,进行改变i18n的参数lang的值,然后重新调用下就可以了. 工程结构: i18n--| |---css ...