[HDU5685]Problem A
来源:
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的更多相关文章
- HDU-5685 Problem A 求乘法逆元
题目链接:https://cn.vjudge.net/problem/HDU-5685 题意 给一个字符串S和一个哈希算法 $ H(s)=\prod_{i=1}^{i\leq len(s)}(S_{i ...
- [HDU5685]2016"百度之星" - 资格赛 Problem A
题目大意:给你一个字符串,和一些问题,每个问题问你[l,r]子串的哈希值是多少. 哈希值计算方法为:$H(s)=\prod _{i=1} ^{i\leq len(s)}(s_i-28)(mod\ 99 ...
- HDU 5685:2016"百度之星" - 资格赛 Problem A
原文链接:https://www.dreamwings.cn/hdu5685/2637.html Problem A Time Limit: 2000/1000 MS (Java/Others) ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- 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 ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
随机推荐
- freeRTOS中文实用教程3--中断管理之中断嵌套
1.前言 最新的 FreeRTOS 移植中允许中断嵌套.中断嵌套需要在 FreeRTOSConfig.h 中设置configKERNEL_INTERRUPT_PRIORITY 和configMAX_S ...
- UML和模式应用3:迭代和进化式分析和设计案例研究
1.前言 如何进行迭代和进化式分析和设计?将采用案例研究的方式贯穿始终.案例研究所包含的内容: UI元素 核心应用逻辑层 数据库访问 与外部软硬构件的协作 本章关于OOA/D主要介绍核心应用逻辑层 2 ...
- FarBox的建站过程
FarBox的建站过程 本文转自:http://mosir.org/html/y2012/How-to-build-your-website-by-farbox.html 作者: mosir 时间: ...
- 关于MySQL 8.0的几个重点【转】
转自 关于MySQL .0的几个重点,都在这里 https://mp.weixin.qq.com/s/QUpk9uuS2JTli1GT6HuORA 一.关于MySQL Server的改进 1.1 re ...
- Ubuntu Eclipse C++运行问题:launch failed.Binary not found
在Ubuntu下的Eclipse C++环境出现launch failed.Binary not found问题时,可采用如下解决方案: (1)首先检查系统中是否成功安装g++.如果console输出 ...
- insmod 时报错“Unknown symbol”问题的解决
在加载驱动模块时报错: “ Unknown symbol CFG80211_SupBandReInit (err 0)” 查看了内核代码以及加载上的symbol(命令为 cat /proc/kalls ...
- spring boot 中的热部署
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>sprin ...
- Android GsmCellLocation.getCellLocation返回NULL
Android GsmCellLocation.getCellLocation返回NULL 1.首先 获取服务 telephonyManager =(TelephonyManager)getSyste ...
- python接口自动化测试二十四:上传多个附件,参数化
# 添加多个附件参数化files = [("1.png", "1.png") ("2.png", "2.png") ]d ...
- MVC开发中的常见错误-05-无法将类型“System.Data.Entity.Infrastructure.DbQuery<BBFJ.OA.Model.RoleInfo>”转换为“System.Collections.Generic.List<BBFJ.OA.Model.RoleInfo>”
List<RoleInfo> roleInfoList = (List<RoleInfo>)ViewBag.AllRoles; 错误原因很明确了 ViewBag.AllRole ...