結果

問題 No.2020 Sum of Common Prefix Length
ユーザー ぷらぷら
提出日時 2022-07-22 22:54:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,175 bytes
コンパイル時間 2,486 ms
コンパイル使用メモリ 221,428 KB
実行使用メモリ 42,732 KB
最終ジャッジ日時 2023-09-17 11:30:10
合計ジャッジ時間 17,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int mod[] = {998244353, 1000000007};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    map<pair<int, int>, int> mp;
    vector<long long> ans(N);
    vector<int> tmp(N);
    vector<vector<vector<int>>> hs(N, vector<vector<int>>(2, vector<int>(1, 0)));
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
        for (int j = 0; j < S[i].size(); j++) {
            for (int k = 0; k < 2; k++) {
                hs[i][k].push_back((27ll * hs[i][k][j] + S[i][j] - 'a' + 1) % mod[k]);
            }
            mp[{hs[i][0][j+1], hs[i][1][j+1]}]++;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < S[i].size(); j++) {
            ans[i] += mp[{hs[i][0][j+1], hs[i][1][j+1]}];
        }
    }
    vector<pair<int,int>> res;
    int Q;
    cin >> Q;
    while (Q--) {
        int f;
        cin >> f;
        if (f == 1) {
            int x;
            char c;
            cin >> x >> c;
            x--;
            S[x] += c;
            res.push_back({x,hs[x][0].size()});
            for (int j = 0; j < 2; j++) {
                hs[x][j].push_back((27ll * hs[x][j][hs[x][j].size()-1] + c - 'a' + 1) % mod[j]);
            }
            mp[{hs[x][0][hs[x][0].size() - 1], hs[x][1][hs[x][1].size() - 1]}]++;
            if (res.size() % 500 == 0) {
                for (int i = 0; i < N; i++) {
                    ans[i] = 0;
                    for (int j = 0; j < S[i].size(); j++) {
                        ans[i] += mp[{hs[i][0][j+1], hs[i][1][j+1]}];
                    }
                }
            }
        }
        else {
            int x;
            cin >> x;
            x--;
            int nans = ans[x];
            for(int i = res.size()/500*500; i < res.size(); i++) {
                if(hs[x][0].size() <= res[i].second) {
                    continue;
                }
                nans += (hs[x][0][res[i].second] == hs[res[i].first][0][res[i].second] && hs[x][1][res[i].second] == hs[res[i].first][1][res[i].second]);
            }
            cout << nans << '\n';
        }
    }
}
0