来源:

2016"百度之星" - 资格赛(Astar Round1)

思路:

首先处理出所有前缀的哈希$f$,对于所有的询问$[a,b]$,答案即为$\frac{f[b]}{f[a-1]}$。
哈希值除法可以通过乘逆元实现。
注意循环时不能直接用$strlen(s)$作为判断条件,
因为$strlen()$函数是$O(n)$的复杂度,这样每次循环都会运行一次,就会把$O(n)$的循环退化成$O(n^2)$的。

 #include<cstdio>
const int LEN=,mod=;
char s[LEN];
int f[LEN]={};
int exgcd(const int a,const int b,int &x,int &y) {
if(!b) {
x=;
y=;
return a;
}
int t=exgcd(b,a%b,y,x);
y-=a/b*x;
return t;
}
int main() {
int n;
while(~scanf("%d",&n)) {
scanf("%s",s);
for(unsigned i=;s[i];i++) {
f[i+]=f[i]*(s[i]-)%mod;
}
while(n--) {
int a,b;
scanf("%d%d",&a,&b);
int x,y;
exgcd(f[a-],mod,x,y);
printf("%d\n",f[b]*(x+mod)%mod);
}
}
return ;
}

[HDU5685]Problem A的更多相关文章

  1. HDU-5685 Problem A 求乘法逆元

    题目链接:https://cn.vjudge.net/problem/HDU-5685 题意 给一个字符串S和一个哈希算法 $ H(s)=\prod_{i=1}^{i\leq len(s)}(S_{i ...

  2. [HDU5685]2016"百度之星" - 资格赛 Problem A

    题目大意:给你一个字符串,和一些问题,每个问题问你[l,r]子串的哈希值是多少. 哈希值计算方法为:$H(s)=\prod _{i=1} ^{i\leq len(s)}(s_i-28)(mod\ 99 ...

  3. HDU 5685:2016"百度之星" - 资格赛 Problem A

    原文链接:https://www.dreamwings.cn/hdu5685/2637.html Problem A Time Limit: 2000/1000 MS (Java/Others)    ...

  4. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  5. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  6. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  7. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  8. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  9. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

随机推荐

  1. dup,dup2函数【转】

    转自:http://eriol.iteye.com/blog/1180624 转自:http://www.cnblogs.com/jht/archive/2006/04/04/366086.html ...

  2. 如何交叉编译 linux kernel 内核

    Compilation We first need to move the config file by running cp arch/arm/configs/bcmrpi_cutdown_defc ...

  3. js 、c# 编码解码

    escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@ ...

  4. exp自动备份在bat中不执行

    在命令行前加cd c:\users\...... 先定位进入可以exp的目录下,再执行exp

  5. 使用NGINX+Openresty和unixhot_waf开源防火墙实现WAF功能

    使用NGINX+Openresty实现WAF功能 一.了解WAF1.1 什么是WAF Web应用防护系统(也称:网站应用级入侵防御系统 .英文:Web Application Firewall,简称: ...

  6. java使用正则表达式的方法从json串儿,取想要的value值

    例子1: 现有json: ({"code":"200","json":["111"],"message&quo ...

  7. 使用swiper.js实现移动端tab切换

    在项目中遇到的,要实现tab切换,我用的是swiper.js 官网:http://www.swiper.com.cn/api/start/new.html <!DOCTYPE html> ...

  8. Java基础96 ajax技术的使用

    本文知识点(目录): 1.ajax的概念   2.使用ajax技术获取服务端的数据_实例   3.使用ajax技术检查用户名是否已存在_实例   4.使用ajax技术验证登录页面的用户名和密码_实例 ...

  9. poj1436水平可见线

    还是线段树区间更新,这次不需要对线段离散化,但是要把线段纵坐标*2,可以举例模拟 #include<iostream> #include<cstring> #include&l ...

  10. python+selenium四:iframe查看、定位、切换

    iframe是HTML里面嵌套HTML的一种框架 1.查看iframe 1.Top Window:可直接定位 2.iframe#i:说明此元素在iframe上 3.iframe显示为空:(id或nam ...