递推 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 ...
随机推荐
- [NOIP2007] 普及组
奖学金 模拟 开个struct排序即可 c++吼啊 /*by SilverN*/ #include<algorithm> #include<iostream> #include ...
- 【HDOJ4812】D Tree(点分治)
题意: 给定一棵 n 个点的树,每个点有权值 Vi 问是否存在一条路径使得路径上所有点的权值乘积 mod(10^6 + 3) 为 K 输出路径的首尾标号,若有多解,输出字典序最小的解 对于100%的数 ...
- 用jQuery向div中添加Html文本内容
前台代码: <link href="http://www.cnblogs.com/Content/themes/base/jquery-ui.css" rel="s ...
- 显示锁ReentrantLock和Condition的使用
一.ReentrantLock (1).java.util.concurrent.locks包中的ReentrantLock就是重入锁,它实现了Lock接口,Lock加锁和解锁都是显示的.Reentr ...
- 激活IDEA 2019.1
First step: 先下载jar包JetbrainsCrack.jar,把它放到你认为合适的文件夹内, 我放在了安装目录C:\Program Files\JetBrains\IntelliJ ID ...
- 立面图 平面图 剖面图 CAD
http://www.qinxue.com/88.html http://www.xsteach.com/course/2855 前后左右各个侧面的外部投影图——立面图:对建筑物各个侧面进行投影所得到 ...
- CCNA参考链接
http://www.cisco.com/c/en/us/support/docs/lan-switching/vtp/10558-21.html http://www.cisco.com/c/en/ ...
- cmd-net命令详解
NET ViewNET UserNET UseNET TimeNet Start Net PauseNet ContinueNET StopNet StatisticsNet Share Net Se ...
- 微信JSSDK使用指南
这篇文章主要来说说微信JSSDK的一些配置和微信分享的使用,包括从前端sdk文件引入到server端和微信server的交互. 另外Tangide已经把一些工作做好了.我会简要说一说怎么把它用 ...
- WebSocket服务端
http://blog.csdn.net/qq_20282263/article/details/54310737 C# 实现WebSocket服务端 原创 2017年01月10日 09:22:50 ...