牛客练习赛33 E. tokitsukaze and Similar String (字符串哈希)
题目链接:https://ac.nowcoder.com/acm/contest/308/E
题意:中文题 见链接
题解:哈希预处理(三哈希模板)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int maxn = 1e5 + ;
const int maxm = 1e5 + ;
const ll mod = 1e9 + ; ll P[] = {,,};
ll MO[] = {mod,mod + ,};
ll T[maxn][];
char s[maxn]; struct node {
ll has[];
}a[maxn][]; int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
for(int i = ; i < ; i++) T[][i] = ;
for(int i = ; i < maxn; i++)
for(int j = ; j < ; j++) T[i][j] = T[i - ][j] * P[j] % MO[j];
int n;
scanf("%d",&n);
scanf("%s",s + );
for(int i = ; i < ; i++)
for(int j = ; j < ; j++) a[][j].has[i] = ;
for(int j = ; j < ; j++) {
for(int i = ; i <= n; i++) {
s[i]++;
if(s[i] > 'z') s[i] -= ;
for(int k = ; k < ; k++) a[i][j].has[k] = (a[i - ][j].has[k] * P[k] % MO[k] + (s[i] - 'a')) % MO[k];
}
}
int q;
scanf("%d",&q);
while(q--) {
int x,y,len;
scanf("%d%d%d",&x,&y,&len);
ll ned[],now[];
for(int i = ; i < ; i++) {
ned[i] = a[y + len - ][].has[i] - a[y - ][].has[i] * T[len][i] % MO[i];
if(ned[i] < ) ned[i] += MO[i];
}
int ans = 1e9;
for(int i = ; i < ; i++) {
bool flag = true;
for(int j = ; j < ; j++) {
now[j] = a[x + len - ][i].has[j] - a[x - ][i].has[j] * T[len][j] % MO[j];
if(now[j] < ) now[j] += MO[j];
if(now[j] != ned[j]) {
flag = false;
break;
}
}
if(flag)
ans = min(ans,min(i, - i));
}
if(ans == 1e9) ans = -;
printf("%d\n",ans);
}
return ;
}
牛客练习赛33 E. tokitsukaze and Similar String (字符串哈希)的更多相关文章
- 牛客练习赛33 E tokitsukaze and Similar String (字符串哈希hash)
链接:https://ac.nowcoder.com/acm/contest/308/E 来源:牛客网 tokitsukaze and Similar String 时间限制:C/C++ 2秒,其他语 ...
- 牛客练习赛33 D tokitsukaze and Inverse Number (树状数组求逆序对,结论)
链接:https://ac.nowcoder.com/acm/contest/308/D 来源:牛客网 tokitsukaze and Inverse Number 时间限制:C/C++ 1秒,其他语 ...
- 牛客练习赛33 C tokitsukaze and Number Game (结论+字符串处理)
链接:https://ac.nowcoder.com/acm/contest/308/C 来源:牛客网 tokitsukaze and Number Game 时间限制:C/C++ 1秒,其他语言2秒 ...
- 牛客练习赛33 B tokitsukaze and RPG (类埃筛)
链接:https://ac.nowcoder.com/acm/contest/308/B 来源:牛客网 tokitsukaze and RPG 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/ ...
- 牛客练习赛50 D tokitsukaze and Event (最短路,思维)
牛客练习赛50 D tokitsukaze and Event 链接:https://ac.nowcoder.com/acm/contest/1080/D来源:牛客网 时间限制:C/C++ 1秒,其他 ...
- 牛客练习赛53 A 超越学姐爱字符串 (DP)
牛客练习赛53 超越学姐爱字符串 链接:https://ac.nowcoder.com/acm/contest/1114/A来源:牛客网 超越学姐非常喜欢自己的名字,以至于英文字母她只喜欢" ...
- 「牛客练习赛53A」超越学姐爱字符串
更好的阅读体验 Portal Portal1: Nowcoder Description 超越学姐非常喜欢自己的名字,以至于英文字母她只喜欢\(\textrm{"c"}\)和\(\ ...
- 牛客练习赛48 C 小w的糖果 (数学,多项式,差分)
牛客练习赛48 C 小w的糖果 (数学,多项式) 链接:https://ac.nowcoder.com/acm/contest/923/C来源:牛客网 题目描述 小w和他的两位队友teito.toki ...
- 牛客练习赛48 A· 小w的a+b问题 (贪心,构造,二进制)
牛客练习赛48 A· 小w的a+b问题 链接:https://ac.nowcoder.com/acm/contest/923/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C ...
随机推荐
- Zero-shot Learning / One-shot Learning / Few-shot Learning
Zero-shot Learning / One-shot Learning / Few-shot Learning Learning类型:Zero-shot Learning.One-shot Le ...
- es6☞对象的解构赋值
变量必须与属性同名 let {name, age} = {name: 'wang', age: 22}; console.log(name, age); //wang 22 let {name} = ...
- Educational Codeforces Round 65 (Div. 2)
A.前n-10个有8即合法. #include<cstdio> #include<cstring> #include<iostream> #include<a ...
- docker 宿主机与容器直接文件移动命令
1.将容器中的文件复制到宿主机 我们把容器中的 nginx 目录整个复制到 宿主机/usr/local/nginx 目录下,使用如下命令: docker cp nginx_test: /etc/ng ...
- ionic开发遇到的问题总结
前言 ionic是一个用来开发混合手机应用的,开源的,免费的代码库.可以优化html.css和js的性能,构建高效的应用程序,而且还可以用于构建Sass和AngularJS的优化.ionic会是一个可 ...
- WPF打印控件内容
当我们想打印控件内容时,如一个Grid中的内容,可以用WPF中PrintDialog类的PrintVisual()方法来实现 界面如下: XAML代码如下 <Grid> <Grid. ...
- 【ES6】数组的扩展
1.Array.from(): 将伪数组对象和遍历的对象转为真数组 如果一个对象的键都是正整数或者0,并且有 Length属性,那么这个对象很想数组,称它为伪数组. 伪数组: let obj = { ...
- SVN_04建库
示范加入一个代码库[Repository] [1]点击Repository右键,创建一个新库 (常规FSFS存储库) [2]在下面所看到的文本框中输入库名称 只创建空的库 创建完库后,没有任何内容在里 ...
- ORACLE大对象存储
--创建有大对象字段的一张表 create table test001 ( fname varchar2(50), content blob ) select * from ...
- 【转载】Sqlserver使用SUBSTRING函数截取字符串
在SQL语句查询过程中,Sqlserver支持使用LEFT().RIGHT().SUBSTRING()等几个函数对字符串进行截取操作,SubString函数相对于其他两个函数来说更灵活,使用场景更多, ...