結果

問題 No.1018 suffixsuffixsuffix
ユーザー potoooooooopotoooooooo
提出日時 2020-04-03 22:43:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,207 bytes
コンパイル時間 1,814 ms
コンパイル使用メモリ 173,076 KB
実行使用メモリ 6,648 KB
最終ジャッジ日時 2023-09-16 03:44:56
合計ジャッジ時間 8,825 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 171 ms
6,516 KB
testcase_10 AC 175 ms
6,552 KB
testcase_11 AC 181 ms
6,460 KB
testcase_12 AC 166 ms
6,456 KB
testcase_13 AC 166 ms
6,460 KB
testcase_14 AC 170 ms
6,348 KB
testcase_15 AC 175 ms
6,364 KB
testcase_16 AC 187 ms
6,416 KB
testcase_17 AC 163 ms
6,432 KB
testcase_18 AC 166 ms
6,372 KB
testcase_19 AC 20 ms
4,376 KB
testcase_20 AC 20 ms
4,380 KB
testcase_21 AC 20 ms
4,376 KB
testcase_22 AC 21 ms
4,376 KB
testcase_23 AC 22 ms
4,376 KB
testcase_24 AC 175 ms
6,124 KB
testcase_25 AC 191 ms
6,392 KB
testcase_26 AC 171 ms
6,088 KB
testcase_27 AC 166 ms
6,108 KB
testcase_28 AC 165 ms
6,108 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 22 ms
4,376 KB
testcase_36 WA -
testcase_37 AC 182 ms
6,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T> struct SuffixArray {
    int N, K;
    vector<int> sa, rank, tmp;

    SuffixArray(int n, T &s) : N(n) {
        sa.resize(N+1);
        rank.resize(N+1);
        tmp.resize(N+1);
        for (int i = 0; i <= N; i++) {
            sa[i] = i;
            rank[i] = i < N ? s[i] : -1; 
        }

        auto compare = [&] (int i, int j) {
            if (rank[i] != rank[j]) return rank[i] < rank[j];
            else {
                int ri = i + K <= N ? rank[i + K] : -1;
                int rj = j + K <= N ? rank[j + K] : -1;
                return ri < rj;
            }
        };

        for (K = 1; K <= N; K <<= 1) {
            sort(sa.begin(), sa.end(), compare);
            tmp[sa[0]] = 0;
            for (int i = 1; i <= n; i++) {
                tmp[sa[i]] = tmp[sa[i-1]] + (compare(sa[i-1], sa[i]));
            }
            for (int i = 0; i <= n; i++) {
                rank[i] = tmp[i];
            }
        }
    }

    // return index of i-th suffix 
    int operator[] (const int &i) const { return sa[i+1]; }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long n, m, q; cin >> n >> m >> q;
    string s; cin >> s;
    s += s;
    SuffixArray<string> sf(n*2, s);
    long long curr = 0; int i = 0;
    vector<long long> ans(q);
    for (int qi = 0; qi < q; qi++) {
        long long k; cin >> k;
        while (curr < k) {
            auto x = sf[i] + 1;
            //cout << qi << " " << curr << " " << k << " " << x << "\n";
            if (x > n) {
                if (curr + 1 < k) {
                    curr++, i++; continue;
                } else if (curr + 1 == k) {
                    ans[qi] = (m-1) * n + (x-n);
                    break;
                }
            } else {
                if (curr + (m-1) < k) {
                    curr += m-1, i++;
                } else {
                    auto y = k - curr;
                    ans[qi] = (m-y-1) * n + x;
                    break;
                }
            }
        }
    }
    for (int i = 0; i < q; i++) {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << "\n";
    return 0;
}
0