結果
問題 | No.2020 Sum of Common Prefix Length |
ユーザー |
|
提出日時 | 2022-07-10 21:58:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,334 bytes |
コンパイル時間 | 4,082 ms |
コンパイル使用メモリ | 254,880 KB |
最終ジャッジ日時 | 2025-01-30 06:18:37 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 TLE * 8 |
ソースコード
#include<bits/stdc++.h>#include<atcoder/all>using namespace std;using namespace atcoder;#define emb emplace_backusing ll = long long;int main(){cin.tie(0);ios::sync_with_stdio(false);//入力int N;cin >> N;vector<string> S(N);for(string &s:S) cin >> s;int node_size = 1;vector<vector<int>> nex(1,vector<int>(26,-1));vector<int> cnt({0});vector<int> node_itr(N);for(int i=0;i<N;i++){int now_node = 0;for(char c:S[i]){int z = c-'a';if(nex[now_node][z] == -1){nex[now_node][z] = node_size++;nex.emplace_back(vector<int>(26,-1));cnt.emplace_back(0);}now_node = nex[now_node][z];cnt[now_node]++;}node_itr[i] = now_node;}int Q;cin >> Q;for(int i=0;i<Q;i++){int t;cin >> t;if(t==1){int x;char c;cin >> x >> c;x--;int z = c-'a';S[x] += c;if(nex[node_itr[x]][z] == -1){nex[node_itr[x]][z] = node_size++;nex.emplace_back(vector<int>(26,-1));cnt.emplace_back(0);}node_itr[x] = nex[node_itr[x]][z];cnt[node_itr[x]]++;}else{int x;cin >> x;x--;int ans = 0,now_node = 0;for(char c:S[x]){now_node = nex[now_node][c-'a'];ans += cnt[now_node];}cout << ans << "\n";}}}