Topic Portal
Test instructions: South P225 of training
Analysis: Binary search length, with hash value to compare the length of the string is equal to the L.
#include <bits/stdc++.h>using namespace Std;typedef unsigned long long ull;const int N = 4e4 + 5;const int x = 123;u ll H[n], _hash[n], xp[n];int rk[n];char str[n];int m;void get_hash (char *s, int len) {H[len] = 0; for (int i=len-1; i>=0;-I.) {H[I] = h[i+1] * x + (S[i]-' a '); } xp[0] = 1; for (int i=1; i<len; ++i) {xp[i] = xp[i-1] * x; }}bool CMP (const int &A, const int &b) {return (_hash[a] < _hash[b] | | (_hash[a] = = _hash[b] && a < b));} int check (int L, int len) {int cnt = 0, pos =-1, c = 0; for (int i=0; i<len-l+1; ++i) {Rk[i] = i; _hash[i] = H[i]-h[i+l] * xp[l]; } sort (RK, rk+len-l+1, CMP); for (int i=0; i<len-l+1; ++i) {if (i = = 0 | | _hash[rk[i]]! = _hash[rk[i-1]]) c = 0; if (++c >= m) pos = max (pos, rk[i]); } return POS;} int main (void) {while (scanf ("%d", &m) = = 1) {if (!m) break; scanf ("%s", &STR); int len = strlen (str); Get_hash (str, len); if (check (1, len) = =-1) puts ("none"); else {int L = 1, r = len + 1; while (R-l > 1) {int mid = L + R >> 1; if (check (mid, Len) >= 0) L = mid; else R = Mid; } printf ("%d%d\n", L, check (L, Len)); }} return 0;}
String hash LA 4513 stammering Aliens