来源:

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. 非root用户执行java进程报错:fork: retry:资源暂时不可用

    vim /etc/security/limits.conf # End of file *           soft   nproc        65535 *           hard   ...

  2. javascript 练习题目答案

    //廖雪峰的博客的这个教程的答案//https://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb300 ...

  3. javascript NaN注意事项

    NaN直译是Not a number NaN是个特殊的number,它和任何值相比都不相等,甚至和它自己. NaN === NaN 这个表达式是false 唯一能判断NaN的方法是 IsNaN(NaN ...

  4. C++ Primer读书笔记(1)

    指针和引用 引用本身不是一个对象,因此不能定义引用的指针:而指针是一个对象,因此可以定义指针的引用. 此外,要理解一个复合类型的变量到底是什么类型,最简单的办法是从右向左阅读其定义,离变量名最近的符号 ...

  5. python之类中的super函数

    作用 实现代码重用 思考:super真的只是调用父类么? super函数是按照mro算法去调用的,不bb上代码: class A: def __init__(self): print('A') cla ...

  6. Java8 容器类详解

      ArrayList Vector CopyOnWriteArrayList LinkedList HashMap ConcurrentHashMap LinkedHashMap 使用场景 随机访问 ...

  7. docker 运行Django项目

    一.概述 已经写好了一个Django项目,需要将这个项目用docker封装一个镜像,使用k8s发布! 在封装并运行的过程中,发现了很多问题,这里会一一介绍! 二.时区问题 采用的是镜像是 ubuntu ...

  8. 正确停止线程的方式三 使用Thread类中的内置的中断标记位-----------不熟悉

    package charpter10; public class Processor implements Runnable { @Override public void run() { for ( ...

  9. Visual Studio强大的帮助工具--Resharper安装与使用

    ReSharper是一个JetBrains公司出品的代码生成工具,其能帮助Microsoft Visual Studio成为一个更佳的IDE.使用ReSharper,你可以进行深度代码分析,智能代码协 ...

  10. 02_kettle插件开发

    先下载标准插件模板    地址     http://www.ahuoo.com/download/TemplateStepPlugin.rar 将下载的jar包解压后  导入eclipse项目中 有 ...