HDU3973——线段树与字符串哈希结合使用
发布时间
阅读量:
阅读量
题解:
给定n个单词以及一个模式串,同时存在两种区间操作类型,分别为单点修改某个单词以及查询某一区间内是否包含特定单词。
我们采用线段树结构来维护区间的哈希值,从而实现对区间查询操作的支持与处理。
#include <bits/stdc++.h>
using namespace std;
#define lson u<<1
#define rson u<<1|1
const int N=1e5+10,p=131;
typedef unsigned long long ull;
set<ull>st;
string str;
ull pre[N];
struct Node{
int l,r;
ull h;
}tr[N<<2];
ull hash_(string a)
{
ull res=0;
for(int i=0;i<a.length();i++) res=res*p+a[i];
return res;
}
void init()
{
pre[0]=1;
for(int i=1;i<N;i++) pre[i]=pre[i-1]*p;
}
void build
全部评论 (0)
还没有任何评论哟~
