QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#47804#4375. Stringckiseki#AC ✓567ms132740kbC++2.1kb2022-09-10 17:15:462022-09-10 17:15:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-10 17:15:50]
  • 评测
  • 测评结果:AC
  • 用时:567ms
  • 内存:132740kb
  • [2022-09-10 17:15:46]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 1000025;

vector<int> buc[maxn];

size_t fail[maxn];
vector<size_t> g[maxn];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        string s;
        int k;
        cin >> s >> k;
        for (size_t i = 1, j = 0; i < s.size(); i++) {
            while (j && s[i] != s[j]) j = fail[j - 1];
            if (s[i] == s[j]) ++j;
            fail[i] = j;
        }

        for (size_t i = 0; i < s.size(); i++) g[i].clear();
        for (size_t i = 0; i < s.size(); i++) {
            g[fail[i]].emplace_back(i + 1);
        }

        vector<int> ans(s.size() + 1);

        const auto In = [&](int i) {
            {
                auto &b = buc[i * 2 % k];
                b.push_back(i * 2);
            }
            {
                const auto &b = buc[i % k];
                // cerr << "i = " << i << ';';
                // for (int j: b)
                //     cerr << j << ',';
                // cerr << endl;
                ans[i] = b.end() - upper_bound(b.begin(), b.end(), i);
            }
        };

        const auto Out = [&](int i) {
            {
                auto &b = buc[i * 2 % k];
                b.pop_back();
            }
        };

        const auto dfs = [&]() {
            vector<int> stk;
            stk.emplace_back(0);
            while (!stk.empty()) {
                int i = stk.back(); stk.pop_back();
                if (i >= 0) {
                    In(i);
                    stk.emplace_back(~i);
                    for (size_t j: g[i]) {
                        stk.emplace_back(j);
                    }
                } else {
                    Out(~i);
                }
            }
        };

        dfs();

        // for (size_t i = 1; i <= s.size(); i++)
        //     cerr << ans[i] << ' ';
        // cerr << endl;
        int64_t res = 1;
        for (size_t i = 1; i <= s.size(); i++)
            res = res * (ans[i] + 1) % mod;
        cout << res << '\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 567ms
memory: 132740kb

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

811844748
106557744
583082277
750875845
539889742
198008691
286657978
344446711
612851418
36100066

result:

ok 10 lines