• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

image

image

单击以查看代码#includeiostream。

使用命名空间std

typedef无符号长ULL;

const int N=1e5 10

const int P=131

int h[N],p[N];

char str[N];

ULL get(int l,int r)

{

return h[r]-h[l-1]* p[r-l 1];

}

int main()

{

int n,m;

CIN n m str 1;

p[0]=1;

for(int I=1;I=n;i ) {

P=P[I-1]* P;

h=h[I-1]* P str

}

while (m - ) {

int l1,r1,l2,R2;

CIN L1 R1 L2 R2;

if (get(l1,r1)==get(l2,R2))puts(' Yes ');

else puts(' No ');

}

返回0;

}

前缀哈希法:一个字符串映射到一个p元整数,映射公式为$(x1pn1x 2pn2xn 1p1xnP0)mod q $。

没有一个字符可以映射到0,因为如果A映射到0,那么AA和AAA也映射到0,不能区分字符数;

问题:Set $ P=131(或13331),q=2 { 64 } $;(所有经验值)

以及前缀公式:$ h=h[I-1]* P str$;

以及区间公式:$ h [l,r]=h[r]-h[l-1]* p { r-L1 } $;

判断字符串是否相等的条件:区间和相等视为相同,区间和不等视为不同;

Link to comment
Share on other sites