文章出处: http://blog.csdn.net/ACM_cxlove?viewmode=contents
原题:http://codeforces.com/problemset/problem/213/E
尼玛,这是研究题解都研究了半天,巨弱啊
开始看成是连续的子串,然后就直接HASH枚举了一下,果断跪。
然后就想到可以不连续,然后就没啥想法了。
最终还是用线段树去维护一个HASH
按数字顺序,依次插入线段树,然后对整个区间求HASH。其实就是比较的是整个区间的相对顺序是否 和A串一致。
比如说A串中是1 3 2
那么将第二个串的1 2 3插入到线段树中后,如果其相对顺序也是1 3 2 那么HASH值肯定一样。
但是注意的是,如果继续插入4,肯定要把1删掉,那么这时候的HASH值是2,3,4的组合HASH。
可以发现每一权都加了1,那么这个预处理一下就可以了
HASH我还是习惯性地两次HASH,减少错误的可能性