QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#662873#21648. RunsQingyyx100 ✓958ms253112kbC++205.7kb2024-10-21 11:33:552024-10-21 11:33:56

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 11:33:56]
  • 评测
  • 测评结果:100
  • 用时:958ms
  • 内存:253112kb
  • [2024-10-21 11:33:55]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int MAXN = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
template <class T = int>inline T read() { T s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline int indi(char* s) { int n = 0; for (s[0] = gc(); !isdigit(s[0]); s[0] = gc()); for (; isdigit(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(auto* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
int n, m, q;
struct Sa {     //俩字符串连一起记得开俩倍空间
    char s[MAXN];
    int SA[MAXN], rk[MAXN], oldrk[MAXN << 1], id[MAXN], key1[MAXN], cnt[MAXN];  //SA排名为i对应原字符串下标,rk下标为i的后缀排名
    int height[MAXN], n;    //height与上一个排名相同的个数,height[1]=0
    inline bool cmp(int x, int y, int w) {
        return oldrk[x] == oldrk[y] && oldrk[x + w] == oldrk[y + w];
    }
    inline void getSA() {
        memset(cnt, 0, sizeof(cnt));
        memset(rk, 0, sizeof(rk));
        n = strlen(s + 1);
        int m = 127;
        for (int i = 1; i <= n; ++i)++cnt[rk[i] = s[i]];
        for (int i = 1; i <= m; ++i)cnt[i] += cnt[i - 1];
        for (int i = n; i >= 1; --i)SA[cnt[rk[i]]--] = i;
        for (int len = 1, p;; len <<= 1, m = p) {
            p = 0;
            for (int i = n; i > n - len; --i)id[++p] = i;
            for (int i = 1; i <= n; ++i)
                if (SA[i] > len)id[++p] = SA[i] - len;
            memset(cnt, 0, sizeof(cnt));
            for (int i = 1; i <= n; ++i)++cnt[key1[i] = rk[id[i]]];
            for (int i = 1; i <= m; ++i)cnt[i] += cnt[i - 1];
            for (int i = n; i >= 1; --i)SA[cnt[key1[i]]--] = id[i];
            memcpy(oldrk + 1, rk + 1, n * sizeof(int));
            p = 0;
            for (int i = 1; i <= n; ++i)
                rk[SA[i]] = cmp(SA[i], SA[i - 1], len) ? p : ++p;
            if (p == n)break;
        }
        // for (int i = 1; i <= n; ++i)printf("%d ", SA[i]); printf("\n");
        // for (int i = 1; i <= n; ++i)printf("%d ", rk[i]); printf("\n");
    }
    inline void getHeight() {
        for (int i = 1, k = 0; i <= n; ++i) {
            if (rk[i] == 0)continue;
            if (k)--k;
            while (s[i + k] == s[SA[rk[i] - 1] + k])++k;
            height[rk[i]] = k;
        }
    }
    int st[MAXN][20], lg[MAXN];
    inline void initST() {
        lg[1] = 0;
        for (int i = 2; i <= n; i++)lg[i] = lg[i >> 1] + 1;
        for (int i = 1; i <= n; i++)st[i][0] = height[i];
        for (int j = 1; j <= lg[n]; j++)
            for (int i = 1; i <= n - (1 << j) + 1; i++)
                st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
    }
    inline int RQM(int x, int y) {
        int t = lg[y - x + 1];
        return min(st[x][t], st[y - (1 << t) + 1][t]);
    }
    inline int LCP(int x, int y) {
        x = rk[x], y = rk[y];
        if (x > y)swap(x, y);
        return RQM(x + 1, y);
    }
}p;
struct Runs {
    char s[MAXN];
    int n;
    Sa sa, rsa;
    int ly[MAXN];
    void init(int _n) {
        n = _n;
        memcpy(sa.s, s, sizeof(s));
        reverse(s + 1, s + 1 + n);
        memcpy(rsa.s, s, sizeof(s));
        reverse(s + 1, s + 1 + n);
        sa.getSA(); sa.getHeight(); sa.initST();
        rsa.getSA(); rsa.getHeight(); rsa.initST();
    }
    int LCP(int x, int y) {
        return sa.LCP(x, y);
    }
    int LCS(int x, int y) {
        return rsa.LCP(n - x + 1, n - y + 1);
    }
    bool compare(int x, int y) {
        int len = LCP(x, y);
        return s[x + len] < s[y + len];
    }
    vector<array<int, 3>>ans;
    void run(int op) {
        for (int i = n - 1; i >= 1; --i) {
            ly[i] = i + 1;
            while (ly[i] && compare(ly[i], i) == op)
                ly[i] = ly[ly[i]];
        }
        for (int i = 1; i <= n; i++) {
            if (!ly[i])continue;
            int x = i, y = ly[i], p = y - x;
            int Lcs = LCS(x, y), Lcp = LCP(x, y);
            int l = x - Lcs + 1, r = y + Lcp - 1;
            if (Lcs + Lcp > p)
                ans.push_back({l, r, p});
        }
    }
    void solve() {
        run(0); run(1);
        sort(all(ans));
        ans.erase(unique(all(ans)), ans.end());
        printf("%d\n", ans.size());
        for (auto [x, y, p] : ans)
            printf("%d %d %d\n", x, y, p);
    }

}run;
void solve() {
    n = inal(run.s + 1);
    run.init(n);
    run.solve();
}
signed main(signed argc, char const* argv[]) {
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    //=============================================================
    int TxT = 1;
    // TxT = read();
    while (TxT--)
        solve();
    //=============================================================
#ifdef LOCAL
    end :
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 50ms
memory: 95192kb

input:

luynenolgrtkiqkdbpcoqsjyisilepmrkleqytdfmxrupcartchjwqhekspohcftpmkpfnwtmoqesqxluevqwewgylwgpdbgplwwbsqpigtayqmswjksngymtwulavrpjpomiedsmxtmpheoqogfwhtpdnaflsxwhlkrrnkfmfrcmvqelyjhfdylszqftndcynurbgwnnnrbkjfxioeptfaoervxgzzhovypdvfsiytviysqpzhkeiyibwhjviqjgpblmieugxroykgnloxpyyzzugirqbcwqdicloyulqij...

output:

7394
99 100 1
164 165 1
200 202 1
222 223 1
277 278 1
279 280 1
334 335 1
406 407 1
410 411 1
412 413 1
421 422 1
434 435 1
458 459 1
494 495 1
559 560 1
564 565 1
566 567 1
577 578 1
624 625 1
633 634 1
704 705 1
706 707 1
710 711 1
749 750 1
769 770 1
797 798 1
800 801 1
858 859 1
866 867 1
868 86...

result:

ok 7395 lines

Test #2:

score: 10
Accepted
time: 77ms
memory: 107932kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

1
1 200000 1

result:

ok 2 lines

Test #3:

score: 10
Accepted
time: 117ms
memory: 93620kb

input:

bbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaaba...

output:

102706
1 2 1
1 27 11
1 70 27
1 183 70
1 479 183
1 1254 479
1 3283 1254
1 8595 3283
1 22502 8595
1 58911 22502
1 154231 58911
3 4 1
5 7 1
7 10 2
10 13 1
12 43 16
12 113 43
12 296 113
12 775 296
12 2029 775
12 5312 2029
12 13907 5312
12 36409 13907
12 95320 36409
12 200000 95320
14 15 1
16 18 1
18 21 ...

result:

ok 102707 lines

Test #4:

score: 10
Accepted
time: 114ms
memory: 95940kb

input:

dcbaabcdabcddcbaabcdabcddcbadcbaabcdabcddcbaabcdabcddcbadcbaabcdabcddcbadcbaabcdabcddcbaabcdabcddcbadcbaabcdabcddcbaabcdabcddcbadcbaabcdabcddcbadcbaabcdabcddcbaabcdabcddcbadcbaabcdabcddcbadcbaabcdabcddcbaabcdabcddcbadcbaabcdabcddcbaabcdabcddcbadcbaabcdabcddcbadcbaabcdabcddcbaabcdabcddcbadcbaabcdabcd...

output:

69092
1 28 12
1 72 28
1 188 72
1 492 188
1 1288 492
1 3372 1288
1 8828 3372
1 23112 8828
1 60508 23112
1 158412 60508
4 5 1
5 12 4
12 13 1
13 44 16
13 116 44
13 304 116
13 796 304
13 2084 796
13 5456 2084
13 14284 5456
13 37396 14284
13 97904 37396
13 200000 97904
16 17 1
17 24 4
24 25 1
25 32 4
29 ...

result:

ok 69093 lines

Test #5:

score: 10
Accepted
time: 4ms
memory: 55748kb

input:

dcbaabcdabcddcbaabcdabcddcbadcbaabcdabcddcbaabcdabcddcbadcbaabcdabcddcbadcbaabcdabcddcbaabcdabcddcba

output:

31
1 28 12
1 72 28
4 5 1
5 12 4
12 13 1
13 44 16
13 100 44
16 17 1
17 24 4
24 25 1
25 32 4
29 56 12
32 33 1
33 40 4
40 41 1
41 88 16
44 45 1
45 52 4
52 53 1
53 60 4
60 61 1
61 68 4
68 69 1
69 76 4
73 100 12
76 77 1
77 84 4
84 85 1
88 89 1
89 96 4
96 97 1

result:

ok 32 lines

Test #6:

score: 10
Accepted
time: 114ms
memory: 107932kb

input:

bbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbaba...

output:

140058
1 2 1
1 34 15
1 87 34
1 227 87
1 594 227
1 1555 594
1 4071 1555
1 10658 4071
1 27903 10658
1 73051 27903
1 191250 73051
2 5 2
2 14 5
3 8 3
5 6 1
6 10 2
8 13 3
10 11 1
11 14 2
14 17 1
15 53 19
15 140 53
15 367 140
15 961 367
15 2516 961
15 6587 2516
15 17245 6587
15 45148 17245
15 118199 45148...

result:

ok 140059 lines

Test #7:

score: 10
Accepted
time: 585ms
memory: 236328kb

input:

ghbaahxvveloseywqeuokpraqgyscdcimfioohjjnwyhdyftczjorapjhncjqetfjetxnfidbgkeesajrjxkkmutayescxxndtmryuubdgijyisstqefcayeycxccwpfpdypautdbbmblfvexakzakgzpfdrdtytyzkytfdwgqarxvyuvivysbzhgcakxbfwarwvxaufsuzprxjnhenbimlqoncmojkqbgoaiifaegpvdakmhxoplzfamkodtatwghwprerxkhtqhfcofqfqrnsgxgjsgcppmlgfrxdceyuo...

output:

38316
4 5 1
8 9 1
36 37 1
39 40 1
76 77 1
84 85 1
94 95 1
102 103 1
111 112 1
124 125 1
137 138 1
158 161 2
229 230 1
273 276 2
287 288 1
342 344 1
352 353 1
412 413 1
449 450 1
458 459 1
463 464 1
514 516 1
564 565 1
588 589 1
621 622 1
630 631 1
653 654 1
678 679 1
682 683 1
689 690 1
776 779 1
78...

result:

ok 38317 lines

Test #8:

score: 10
Accepted
time: 553ms
memory: 251072kb

input:

pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp...

output:

1
1 999998 1

result:

ok 2 lines

Test #9:

score: 10
Accepted
time: 958ms
memory: 253112kb

input:

aababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccabbccaaababbbbccaaababbbbccabbccaaababbbbccaaaba...

output:

513547
1 2 1
1 43 16
1 113 43
1 296 113
1 775 296
1 2029 775
1 5312 2029
1 13907 5312
1 36409 13907
1 95320 36409
1 249551 95320
1 653333 249551
2 5 2
5 8 1
7 16 5
9 10 1
12 13 1
12 70 27
12 183 70
12 479 183
12 1254 479
12 3283 1254
12 8595 3283
12 22502 8595
12 58911 22502
12 154231 58911
12 40378...

result:

ok 513548 lines

Test #10:

score: 10
Accepted
time: 921ms
memory: 251248kb

input:

aababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbabaababaababbbbabaababaababbbbabbbaba...

output:

700312
1 2 1
1 10 5
1 53 19
1 140 53
1 367 140
1 961 367
1 2516 961
1 6587 2516
1 17245 6587
1 45148 17245
1 118199 45148
1 309449 118199
1 810148 309449
2 6 2
4 9 3
6 7 1
7 10 2
8 17 5
10 13 1
11 19 4
15 17 1
15 87 34
15 227 87
15 594 227
15 1555 594
15 4071 1555
15 10658 4071
15 27903 10658
15 730...

result:

ok 700313 lines