140. 后缀数组(hash + 二分 / 后缀数组)
题目链接 : https://www.acwing.com/problem/content/description/142/ Hash + 二分 #include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 7; typedef unsigned long long ull; const ull mod = 131; ull p[maxn],h[maxn]; int sa[maxn],rank[maxn],height[maxn]; char str[maxn]; int n ; ull get(int x,int y){ return h[y] - h[x - 1] * p[y - x + 1]; } int lcp(int x,int y){ int l = 0 ,r = min(n - x + 1,n - y + 1); while(l < r){ int mid = (l + r + 1) >> 1; if(get(x,x + mid - 1) != get(y,y + mid - 1)) r = mid - 1; else l = mid; } return l; } bool cmp(int x , int y){ int l = lcp(x,y); int av = x + l > n ?