int main() {
	int runs;
	scanf("%d", &runs);
	for (int run = 1; run <= runs; ++run) {
		scanf("%s", str);
		int ls = strlen(str);
		for (int i = 0; i < ls; ++i) num[i] = str[i];
		num[ls] = 1;
		for (int i = 0; i < ls; ++i) num[ls + 1 + i] = str[ls - i - 1];
		num[ls+ls+1] = 0;
		sa.init(num, ls + ls + 1, 128);
		sa.init_rmq();
		memset(vis, 0, sizeof(vis));
		int ans = 0, cnt = 0;
		for (int i = 1; i <= ls+ls; ++i) {
			cnt = min(cnt, sa.height[i]);
			if (!vis[sa[i]] && vis[ls+ls+1-sa[i]+1]) {
				int t = sa.lcp(sa[i], ls+ls+1-sa[i]+1);
				if (t <= cnt) continue;
				ans += t - cnt;
				if (cnt < t) ans = t;
			} else vis[sa[i]] = 1;
		}
		printf("%d\n", ans);
	}
	return 0;
}
Beispiel #2
0
int main() {
    int n, m, l, r;
    set<pair<int, int> > st;

    scanf("%d%d", &n, &m);
    scanf("%s", buf);
    sa.init(n, buf);
    rmq.init(n, sa.height);

    l = 0;
    r = 1;
    for (int i = 0; i < m; ++i) {
        scanf("%s", op);
        int& t = op[0] == 'L' ? l : r;
        t += op[1] == '+' ? 1 : -1;
        int k = sa.rank[l];
        int lo = 0, hi = k;
        while (lo < hi) {
            int mi = (lo + hi) / 2;
            if (rmq.value(mi + 1, k + 1) >= r - l) {
                hi = mi;
            } else {
                lo = mi + 1;
            }
        }
        st.insert(make_pair(hi, r - l));
    }
    printf("%d\n", (int)st.size());

    return 0;
}
Beispiel #3
0
 static void init_suffix_array( const String& s, SuffixArray& sa ) {
   sa.init(s);
   sa.build();
   sa.buildHeight();
 }