hdu 5685(逆元)
Problem A
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 520 Accepted Submission(s): 203
H(s)=∏i≤len(s)i=1(Si−28) (mod 9973)
Si代表 S[i] 字符的 ASCII 码。
请帮助度熊计算大字符串中任意一段的哈希值是多少。
1≤N≤1,000
1≤len(string)≤100,000
1≤a,b≤len(string)
ACMlove2015
1 11
8 10
1
testMessage
1 1
9240
88
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
using namespace std;
typedef long long LL;
const int N = ;
char str[N];
LL inv[]; ///逆元
LL num[N];
LL extend_gcd(LL a,LL b,LL &x,LL &y){
if( b == ) {
x = ;
y = ;
return a;
}
else{
LL x1,y1;
LL d = extend_gcd (b,a % b,x1,y1);
x = y1;
y= x1 - a / b * y1;
return d;
}
}
LL mod_reverse(LL a,LL n)
{
LL x,y;
LL d=extend_gcd(a,n,x,y);
if(d==) return (x%n+n)%n;
else return -;
}
void init(){
inv[] = ,inv[]=;
for(int i=;i<=;i++){
inv[i] = mod_reverse(i,);
}
}
int main()
{
int m;
init();
while(~scanf("%d",&m)){
scanf("%s",str+);
int len = strlen(str+);
num[] = str[]-;
for(int i=;i<=len;i++){
int x = str[i]-;
num[i] = (num[i-]*x)%;
}
while(m--){
int l,r;
scanf("%d%d",&l,&r);
if(l==) printf("%d\n",num[r]);
else printf("%lld\n",num[r]*inv[num[l-]]%); ///(num[r]/num[l-1])%9973
}
}
}
hdu 5685(逆元)的更多相关文章
- HDU - 5685 Problem A(逆元)
这题我第一次想的就是直接模拟,因为我是这样感觉的,输入n是3次方,长度是5次方,加起来才8次方,里面的操作又不复杂,感觉应该能过,然而不如我所料,TLE了,玛德,这是第一次的代码. #include ...
- hdu 5685 Problem A (逆元)
题目 题意:H(s)=∏i≤len(s)i=1(Si−28) (mod 9973),求一个字符串 子串(a 位到 b 位的)的哈希值.这个公式便是求字符串哈希值的公式,(字符的哈希值 = 字符的ASC ...
- HDU 5685 Problem A | 快速幂+逆元
Problem A Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- HDU 5685:2016"百度之星" - 资格赛 Problem A
原文链接:https://www.dreamwings.cn/hdu5685/2637.html Problem A Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 5685 Problem A
Problem Description 度熊手上有一本字典存储了大量的单词,有一次,他把所有单词组成了一个很长很长的字符串.现在麻烦来了,他忘记了原来的字符串都是什么,神奇的是他竟然记得原来那些字符串 ...
- hdu 1211 逆元
RSA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 4828 逆元+catalan数
Grids Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- HDU 5651 逆元
xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- hdu 1576(逆元)
A/B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- yii2 RUL的生成
通常情况下,会使用 yii\helpers\Url 使用Url类来生成想要的URL地址(链接) Url提供的方法大都是静态方法,不需要对类进行实例化 1.1 最常用的 Url::to() 1.2. b ...
- 关于request.getServletContext()方法报错的问题
可以通过修改pom文件来添加一个javax.servlet-api-3.1.0.jar的jar包,找到你的pom.xml文件添加代码如下: <dependency> <groupId ...
- wireshark_1.6.2 使用笔记
表示ip1是否有访问ip2,进行抓包
- Python中的bytes
bytes_lst = [ ('创建bytes',), ('bytes可哈希',), ('编码与解码',), ('常见编码类型',), ('ord() 与 chr()',), ] 创建bytes &g ...
- A JavaScript Image Gallery
childNodes property: The childNodes property is a way of getting information about the children of ...
- python项目中输出指定颜色的日志
起因 在开发项目过程中,为了方便调试代码,经常会向stdout中输出一些日志,默认的这些日志就直接显示在了终端中.而一般的应用服务器,第三方库,甚至服务器的一些通告也会在终端中显示,这样就搅乱了我们想 ...
- 极简Node教程-七天从小白变大神(二:中间件是核心)
当我们只引入express时,前述的那些功能都是没有启用的.那么,如何将这些功能添加进来呢?express通过其中间件机制实现了这些功能的管理.每一个中间件对应一个功能,而中间件可以是第三方库,也可以 ...
- Appium的三种等待时间设置方法
#三种appium设置等待时间的方法 #作者:Mr.Dantes #参考了网上的资料,然后进行了梳理 #第一种 sleep(): 设置固定休眠时间. python 的 time 包提供了休眠方法 ...
- linux常用的日志分析脚本
linux实用的日志分析脚本 日志分析 随意的tail一个access_log文件,下面是一条经典的访问记录 /Dec/::: +] “GET /query/trendxml/district/tod ...
- python学习-- settings 设置sqlserver连接
PyCharm 开发工具 先打开项目 1. ctrl+alt+s 2. project:项目名称 选中Project Interpreter,点右面+号 :搜索 django-pyodbc-az ...