結果
| 問題 | No.3667 Prefix Count Queries |
| ユーザー |
|
| 提出日時 | 2026-09-17 14:49:44 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 29 ms / 2,000 ms |
| + 193µs | |
| コード長 | 1,117 bytes |
| 記録 | |
| コンパイル時間 | 2,267 ms |
| コンパイル使用メモリ | 339,620 KB |
| 実行使用メモリ | 33,568 KB |
| 最終ジャッジ日時 | 2026-10-23 04:58:31 |
| 合計ジャッジ時間 | 5,511 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
struct Vertex {
int next[26];
int prv = -1;
int count = 0;
Vertex() { fill(begin(next), end(next),-1); }
};
vector<Vertex> trie(1);
void add_string(const string& s) {
int v = 0;
trie[v].count+=1;
for(char ch: s) {
int c = ch - 'a';
if (trie[v].next[c] == -1) {
trie[v].next[c] = trie.size();
trie.emplace_back();
}
v = trie[v].next[c];
trie[v].count += 1;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
for(int i = 0; i < N; i++) {
string s;
cin >> s;
add_string(s);
}
int it = 0;
int ans = trie[it].count;
int Q;
cin >> Q;
while(Q--) {
int op;
cin >> op;
if (op == 1) {
char x;
cin >> x;
int c = x - 'a';
if (trie[it].next[c] == -1) {
trie[it].next[c] = trie.size();
trie.emplace_back();
}
trie[trie[it].next[c]].prv=it;
it = trie[it].next[c];
} else if(op == 2) {
it=trie[it].prv;
} else {
cout<<trie[it].count<<"\n";
}
}
}