题目链接

题意:一个只含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的更多相关文章

  1. 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优

    libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...

  2. Struts2 easy UI插件

    一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...

  3. Easy UI常用插件使用

    一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...

  4. UVA-11991 Easy Problem from Rujia Liu?

    Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...

  5. 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 ...

  6. easy ui插件

    简介: easy UI是类似于jQuery UI的插件库 注意:多脚本同时使用时,注意脚本冲突问题. 常用插件: 1.tree插件(tree插件实现动态树形菜单) 2.datagrid插件(datag ...

  7. 用TPP开启TDD的easy模式

    Test-Drived Development 测试驱动开发三步曲:写一个失败的测试用例->编写生产代码通过这个测试用例(transformation)->重构(refactor).重构是 ...

  8. Easy Sysprep更新日志-skyfree大神

    Easy Sysprep更新日志: Skyfree 发表于 2016-1-22 13:55:55 https://www.itsk.com/forum.php?mod=viewthread&t ...

  9. [官方软件] 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 ...

  10. [原创] Easy SysLite V1.2 (2016.5.29更新,新增加WIN10支持,一个程序适配所有系统减肥)

    [原创] Easy SysLite V1.2 (2016.5.29更新,新增加WIN10支持,一个程序适配所有系统减肥) nohacks 发表于 2016-5-29 17:12:51 https:// ...

随机推荐

  1. Docker Centos安装Mysql5.6

    之前一篇随笔<Docker Centos安装Openssh> 写的是如何在基础的centos镜像中搭建ssh服务,在此基础上再搭建其他服务.本文继续介绍在centos_ssh基础上搭建my ...

  2. keepalived + nginx双主 实战

    安装nginx nginx 下载地址 http://nginx.org/download/nginx-1.8.0.tar.gz 安装nginx的依赖关系 yum install pcre pcre-d ...

  3. vscode使用php调试

    1:首先查看是否安装xdebug扩展 打开终端  ➜ ~ php -vPHP 5.6.24 (cli) (built: Jul 21 2016 14:27:54) Copyright (c) 1997 ...

  4. c3p0数据库连接池(作用不重复)

    /* * c3p0数据库连接池: * 只被初始化一次 * connection对象进行close时,不是正的关闭,而是将该数据连接归还给数据库连接池 * * */ 四个架包 mysql-connect ...

  5. Dual Core CPU

    Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 20935 Accepted: 9054 Case ...

  6. hiho一下,第115周,FF,EK,DINIC

    题目1 : 网络流一·Ford-Fulkerson算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho住在P市,P市是一个很大很大的城市,所以也面临着一个 ...

  7. C#中的字符串处理——找出最长数字子串

    百度测试部2015年10月份的面试题之——字符串处理,找出最长的子串. 代码如下: private static string SelectNumberFromString(string input) ...

  8. thinkphp 删除多条记录

    删除id为123456的记录 $ids=array(1,2,3,4,5,6);$maps["id"] = array("in",$ids);$this-> ...

  9. hdu Interesting Fibonacci

    Interesting Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  10. yum报错

    用man clean all man yum,可以看到,clean选项的作用是: Is  used  to clean up various things which accumulate in th ...