【BZOJ】【P2258】【pku2758 Checking the Text 文本校对】【题解】【hash】
来源:互联网 发布:许佳琪吴哲晗吵架知乎 编辑:程序博客网 时间:2024/06/07 12:23
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2258
明天就初赛了
刷水娱♂乐身心
Code:
#include<cstdio>#include<cctype>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=50300;typedef unsigned long long UL;UL base=233;UL hash[maxn];UL hash_l[maxn];char s[maxn];int len,m;void hash_init(int be){UL val=hash[be-1];for(int i=be;i<=len;i++){val=val*base+s[i]-'a';hash[i]=val;}}int mp[maxn+200];int main(){scanf("%s",s+1);s[0]='#';len=strlen(s+1);hash_l[0]=1;for(int i=1;i<=len+200;i++)hash_l[i]=hash_l[i-1]*base,mp[i]=i;scanf("%d",&m);hash_init(1);while(m--){char op=getchar();while(op!='Q'&&op!='I')op=getchar();if(op=='I'){char x=getchar();while(!isalpha(x))x=getchar();int ps;scanf("%d",&ps);if(ps>len)ps=len+1;for(int i=len+1;i>ps;i--)s[i]=s[i-1];for(int j=lower_bound(mp+1,mp+1+len,ps)-mp,i=j;i<=len+1;i++)mp[i]++;s[ps]=x;len++;s[len+1]='\0';hash_init(ps);}else{int a,b;scanf("%d%d",&a,&b);a=mp[a];b=mp[b];int l=0,r=len-b+2;while(l<r){int mid=(l+r)>>1;if(hash[a+mid-1]-hash[a-1]*hash_l[mid]==hash[b+mid-1]-hash[b-1]*hash_l[mid])l=mid+1;else r=mid;}printf("%d\n",l-1);}}return 0;}
0 0
- 【BZOJ】【P2258】【pku2758 Checking the Text 文本校对】【题解】【hash】
- BZOJ 2258 pku2758 Checking the Text 文本校对 Splay+Hash
- bzoj 2258: pku2758 Checking the Text 文本校对 hash+二分
- bzoj2258: pku2758 Checking the Text 文本校对 hash+二分
- BZOJ 2258 pku2758 Checking the Text 文本校对 Splay+Hash+二分
- poj 2758: Checking the Text(二分+Hash)
- 【bzoj2258】【文本校对】【splay+hash】
- poj2758 checking the text
- poj2758 checking the text
- Poj2758 Checking the Text
- poj-2758 Checking the Text
- POJ 2758 Checking the Text
- POJ 2758 Checking the Text
- poj 2758 Checking the text
- 后缀数组 - poj2758 Checking the Text
- 洛谷 P2258 子矩阵 题解
- BZOJ2258 文本校对 (Splay Hash 二分答案)
- poj 2758 Checking the Text (后缀数组应用)
- sharedpreference中putStringSet和getStringSet的问题
- Qt:内建对话框
- php之字符串处理
- 杭电2072 单词数
- How to install GSL on linux (ubuntu)
- 【BZOJ】【P2258】【pku2758 Checking the Text 文本校对】【题解】【hash】
- Eclipse的命令行输入
- LauchMode页面加载模式
- poi读取excel带下拉框的单元格
- JQuery IE下如何阻止keydown事件冒泡
- 使用spring-remoting,解决HessianProtocolException: expected string at 0x6d
- 盘点冬季皮肤保养的十大陷阱
- 每日小记~10~11
- 小编总结:理财技能GET