結果
| 問題 | No.3667 Prefix Count Queries |
| ユーザー |
|
| 提出日時 | 2026-09-17 14:49:44 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 28 ms / 2,000 ms |
| + 816µs | |
| コード長 | 1,117 bytes |
| 記録 | |
| コンパイル時間 | 2,137 ms |
| コンパイル使用メモリ | 335,316 KB |
| 実行使用メモリ | 32,544 KB |
| 最終ジャッジ日時 | 2026-09-17 14:49:52 |
| 合計ジャッジ時間 | 6,830 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
#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";
}
}
}