QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#271925#7876. Cyclic Substringsucup-team037#AC ✓1129ms969568kbC++173.9kb2023-12-02 15:15:182023-12-02 15:15:19

Judging History

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

  • [2023-12-02 15:15:19]
  • 评测
  • 测评结果:AC
  • 用时:1129ms
  • 内存:969568kb
  • [2023-12-02 15:15:18]
  • 提交

answer


// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 3000005;
const int MOD = 998244353;

const char STARTC = '0';
const int MAXC = 10;
struct Eertree {
    struct Node {
        int len, link, id;
        int nxt[MAXC];
        Node() {
            memset(nxt, 0, sizeof nxt);
        }
        Node(int _len, int _link, int _id): Node() {
            len = _len;
            link = _link;
            id = _link;
        }

    };
    vector<Node> v;
    string s;
    int rt;
    Eertree() {
        v.pb({-1, 0, -1});
        v.pb({0, 0, -1});
        rt = 1;
    }
    bool insert(char c) {
        s += c;
        int u = rt;
        while (u && (SZ(s) - v[u].len - 2 < 0 || 
                    s[SZ(s) - v[u].len - 2] != c)) {
            u = v[u].link;
        }
        if (v[u].nxt[c - STARTC]) {
            rt = v[u].nxt[c - STARTC];
            return 0;
        }
        rt = SZ(v);
        v[u].nxt[c - STARTC] = SZ(v);
        Node nw;
        nw.id = SZ(s) - 1;
        nw.len = v[u].len + 2;
        if (nw.len == 1) {
            nw.link = 1;
        } else {
            u = v[u].link;
            while (u && (SZ(s) - v[u].len - 2 < 0 || 
                        s[SZ(s) - v[u].len - 2] != c)) {
                u = v[u].link;
            }
            nw.link = v[u].nxt[c - STARTC];
        }
        v.pb(nw);
        return 1;
    }
} et;

int n;
string s;
int p[2 * MAXN];
int jump[2 * MAXN], depth[2 * MAXN];
vi adj[2 * MAXN];
int ev[2 * MAXN];
int psm[2 * MAXN];
ll ans;

int pre[2 * MAXN], pst[2 * MAXN], ptr = 1;
void dfs(int u) {
    pre[u] = ptr++;
    for (int v : adj[u]) {
        dfs(v);
    }
    pst[u] = ptr;
}

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n;
    cin >> s;
    p[1] = 1;
    jump[1] = 1;
    depth[1] = 0;
    REP (i, 0, n * 2) {
        if (et.insert(s[i % n])) {
            int tp = et.v[et.rt].link;
            p[et.rt] = tp;
            depth[et.rt] = depth[tp] + 1;
            adj[tp].pb(et.rt);
            if (depth[tp] - depth[jump[tp]] == depth[jump[tp]] -
                    depth[jump[jump[tp]]]) {
                jump[et.rt] = jump[jump[tp]];
            } else {
                jump[et.rt] = tp;
            }
        }
        int v = et.rt;
        while (et.v[v].len > n) {
            if (et.v[jump[v]].len > n) {
                v = jump[v];
            } else {
                v = p[v];
            }
        }
        int u = et.rt;
        while (i - et.v[u].len + 1 < n && u != 1) {
            if (i - et.v[jump[u]].len + 1 < n) {
                u = jump[u];
            } else {
                u = p[u];
            }
        }
        ev[v]++;
        ev[u]--;
    }
    dfs(1);
    REP (i, 2, SZ(et.v)) {
        psm[pre[i]] = ev[i];
    }
    REP (i, 1, SZ(et.v) + 5) {
        psm[i] += psm[i - 1];
    }
    REP (i, 2, SZ(et.v)) {
        ll f = psm[pst[i] - 1] - psm[pre[i] - 1], g = et.v[i].len;
        ans += f * f % MOD * g % MOD;
    }
    ans %= MOD;
    cout << ans << '\n';
    return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 12ms
memory: 153348kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 12ms
memory: 153048kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 18ms
memory: 153136kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 12ms
memory: 153120kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 12ms
memory: 153068kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 8ms
memory: 155112kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 20ms
memory: 153056kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 357ms
memory: 434112kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 1129ms
memory: 969568kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 320ms
memory: 442028kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 1063ms
memory: 886068kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 1050ms
memory: 858292kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 509ms
memory: 709696kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 458ms
memory: 714328kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 459ms
memory: 460388kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 165ms
memory: 260180kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 637ms
memory: 698832kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 595ms
memory: 706064kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed