結果

問題 No.2020 Sum of Common Prefix Length
ユーザー ぷらぷら
提出日時 2022-07-22 22:31:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,501 bytes
コンパイル時間 2,327 ms
コンパイル使用メモリ 214,844 KB
実行使用メモリ 28,372 KB
最終ジャッジ日時 2023-09-17 10:58:34
合計ジャッジ時間 15,929 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 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 TLE -
testcase_16 -- -
testcase_17 -- -
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>,vector<int>>mp;
    vector<long long>ans(N);
    vector<int>tmp(N);
    vector<vector<int>>hs(N,vector<int>(2,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] = (27ll*hs[i][k]+S[i][j]-'a')%mod[k];
            }
            mp[{hs[i][0],hs[i][1]}].push_back(i);
        }
    }
    for(int i = 0; i < N; i++) {
        hs[i][0] = hs[i][1] = 0;
        for(int j = 0; j < S[i].size(); j++) {
            for(int k = 0; k < 2; k++) {
                hs[i][k] = (27ll*hs[i][k]+S[i][j]-'a')%mod[k];
            }
            ans[i] += mp[{hs[i][0],hs[i][1]}].size();
        }
    }
    int Q;
    cin >> Q;
    while(Q--) {
        int f;
        cin >> f;
        if(f == 1) {
            int x;
            char c;
            cin >> x >> c;
            x--;
            for(int j = 0; j < 2; j++) {
                hs[x][j] = (27ll*hs[x][j]+c-'a')%mod[j];
            }
            mp[{hs[x][0],hs[x][1]}].push_back(x);
            for(int i:mp[{hs[x][0],hs[x][1]}]) {
                ans[i]++;
            }
        }
        else {
            int x;
            cin >> x;
            x--;
            cout << ans[x] << '\n';
        }
    }
}
0