As Easy As Possible
题意:一个只含e, a, s, y的字符串,问[l, r]内有多少个easy序列?
题解:倍增。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+;
char s[N];
int id(char c){
if(c == 'e') return ;
if(c == 'a') return ;
if(c == 's') return ;
return ;
}
int Log[N];
int f[][N], nex[N][];
int main(){
for(int i = ; i < N; i++) Log[i] = Log[i>>]+;
scanf("%s", s+);
int len = strlen(s+);
int last[];
last[] = last[] = last[] = last[] = len+;
for(int i = len; i; i--){
int k = id(s[i]);
last[k] = i;
for(int j = ; j < ; j++)
nex[i][j] = last[j];
}
//nex[i][k]: [i, len]中第一个k出现的位置
for(int i = ; i <= len; i++){
f[][i] = nex[i][];
for(int j = ; j < &&f[][i] <= len; j++)
f[][i] = nex[f[][i]][j];
}
//f[0][i]: [i, len]中第一个出现easy的结尾处
for(int j = ; j <= Log[len]; j++)
for(int i = ; i <= len; i++){
int pos = f[j-][i];
f[j][i] = pos > len? pos : f[j-][pos];
} int m, l, r;
scanf("%d", &m);
while(m--){
scanf("%d%d", &l, &r);
int ans = ;
for(int i = Log[len]; i >= &&l < r; i--){
if(f[i][l] > r) continue ;
ans += <<i;
l = f[i][l]+;
}
printf("%d\n", ans);
}
return ;
}
As Easy As Possible的更多相关文章
- 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优
libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...
- Struts2 easy UI插件
一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...
- Easy UI常用插件使用
一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- CodeForces462 A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...
- easy ui插件
简介: easy UI是类似于jQuery UI的插件库 注意:多脚本同时使用时,注意脚本冲突问题. 常用插件: 1.tree插件(tree插件实现动态树形菜单) 2.datagrid插件(datag ...
- 用TPP开启TDD的easy模式
Test-Drived Development 测试驱动开发三步曲:写一个失败的测试用例->编写生产代码通过这个测试用例(transformation)->重构(refactor).重构是 ...
- Easy Sysprep更新日志-skyfree大神
Easy Sysprep更新日志: Skyfree 发表于 2016-1-22 13:55:55 https://www.itsk.com/forum.php?mod=viewthread&t ...
- [官方软件] Easy Sysprep v4.3.29.602 【系统封装部署利器】(2016.01.22)--skyfree大神
[官方软件] Easy Sysprep v4.3.29.602 [系统封装部署利器](2016.01.22) Skyfree 发表于 2016-1-22 13:55:55 https://www.it ...
- [原创] Easy SysLite V1.2 (2016.5.29更新,新增加WIN10支持,一个程序适配所有系统减肥)
[原创] Easy SysLite V1.2 (2016.5.29更新,新增加WIN10支持,一个程序适配所有系统减肥) nohacks 发表于 2016-5-29 17:12:51 https:// ...
随机推荐
- Linux之查看CPU信息
# 查看逻辑CPU个数: # cat /proc/cpuinfo |grep "processor"|sort -u|wc -l 24 # 查看物理CPU个数: # grep &q ...
- Codeforces 741B:Arpa's weak amphitheater and Mehrdad's valuable Hoses(01背包+并查集)
http://codeforces.com/contest/741/problem/B 题意:有 n 个人,每个人有一个花费 w[i] 和价值 b[i],给出 m 条边,代表第 i 和 j 个人是一个 ...
- LA 4998 Simple Encryption
题意:输入正整数$K_1(K_1 \leq 50000)$, 找一个$12$位正整数$K_2$(不能含有前导零)使得${K_1}^{K_2}\equiv K_2(mod10^{12})$. 例如,$K ...
- (POJ2635)The Embarrassed Cryptographer(大数取模)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13041 Accep ...
- Uva 12186 工人的请愿书
题目链接:https://uva.onlinejudge.org/external/121/12186.pdf 题意: 给出一个树状关系图,公司里只有一个老板编号为0,其他人员从1开始编号.除了老板, ...
- js九九乘法表
<!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...
- 2016 Al-Baath University Training Camp Contest-1 G
Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...
- Android各种获取Context方法
首先讲一讲这四个函数的区别,后面还有我对context的一些理解区别如下所示: 原文链接http://stackoverflow.com/questions/6854265/getapplicatio ...
- Intent传递对象——Serializable和Parcelable区别
为什么要将对象序列化? 1.永久性保存对象,保存对象的字节序列到本地文件中: 2.用过序列化对象在网络中传递对象: 3.通过序列化对象在进程间传递对象. 1.实现Serializable接口 Seri ...
- html body的属性 格式控制标签 内容容器标签 超链接标签 图片标签 表格
一.body的属性 <body bgcolor 页面背景色 background 背景壁纸.图片 text文字颜色 topmargin上边距 leftmargin左边距 rightmargi ...