递推 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 ...
随机推荐
- [ 浙江大学 程序设计专题 ] 四个专题代码 报告 PPT共享
[原创]转载请注明出处,请勿用于作弊 专题一: 链接: https://pan.baidu.com/s/11xCwvuPHDkTPeOB_yzJWnw 提取码: prup 专题二: 链接: https ...
- [NOIP2007] 提高组 洛谷P1097 统计数字
题目描述 某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*10^9).已知不相同的数不超过10000个,现在需要统计这些自然数各自出现的次数,并按照自然数从小到大的顺序输出 ...
- js数组转换成json串 (JSON.stringify)
例如: var giftlist[1490011777] = []; giftlist[1490011777]['id'] = 1490011777; giftlist[1490011777]['na ...
- ***mysql 用一个表的一列,去更新另一表的一列
需求: 老板给了一个EXCEL数据,是本人提供的一个模板,含ID,现在相当于要导入这新增的一列数据到数据库中的某一个表. 方法一:用navicat,在excel中复制一列,再粘贴到navicat中的一 ...
- React Native学习(五)—— 使用插件react-native-scrollable-tab-view
本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...
- Spring基础入门(三)
一.Spring的jdbcTemplate操作 (1)Spring是一站式框架,对于javaee三层,每一层都有解决技术. web层:springMVC service:spring的ioc dao层 ...
- Ubuntu 16.04中XMind 8导致Java内存溢出的问题解决(硬盘卡死,桌面卡死)
XMind使用的是Java进行开发,如果出现内存溢出的问题,那么一定是桌面快捷方式的问题,解决方法是直接修改快捷方式里面的内容,修改如下: [Desktop Entry] Encoding=UTF-8 ...
- cn_windows_10_multiple_editions_version_1607_updated_jul_2016_x64
ed2k://|file|cn_windows_10_multiple_editions_version_1607_updated_jul_2016_x64_dvd_9056935.iso|43471 ...
- MongoDB小结24 - 索引简介2
索引的名字 集合中每个索引都有一个字符串类型的名字,来唯一标识索引. 服务器通过名字来操作或者删除索引. 要注意的是,索引名有字符个数限制,所以索引创建时一定要用自定义的名字,如 db.user.en ...
- Mysql入门实战中
前面一章主要解说了mysql的入门学习.包括数据库,表的管理,以及对数据的增删改,本章主要介绍mysql最重要的语句select的使用方法.将select的大部分使用方法进行分别解说. 全部代码下载( ...