2
using ull = unsigned long long;5
string longestDupSubstring(string s) {7
vector<ull> power(n, 1);8
for (int i = 1; i < n; i++) {9
power[i] = power[i - 1] * 27;11
return solve(s, power);14
string solve(string &s, vector<ull> &power) {15
int low = 1, high = s.size();17
int mid = low + (high - low) / 2;18
if (check(s, mid, power) != -1) {24
int start = check(s, low - 1, power);25
if (start > 0) return s.substr(start, low - 1);29
int check(string &s, int len, vector<ull> &power) {30
if (len <= 0) return -1;31
unordered_set<ull> st;33
for (int i = 0; i < len; i++) {34
curr_hash = curr_hash + power[len - i - 1] * (s[i] - 'a');37
for (int i = len; i < s.size(); i++) {38
curr_hash = curr_hash - power[len - 1] * (s[i - len] - 'a');39
curr_hash = curr_hash * 27;40
curr_hash = curr_hash + (s[i] - 'a');41
if (st.count(curr_hash)) {