結果
| 問題 | No.3667 Prefix Count Queries |
| ユーザー |
👑 |
| 提出日時 | 2026-08-31 22:09:15 |
| 言語 | PyPy3 (7.3.23) |
| 結果 |
AC
|
| 実行時間 | 439 ms / 2,000 ms |
| + 81µs | |
| コード長 | 865 bytes |
| 記録 | |
| コンパイル時間 | 472 ms |
| コンパイル使用メモリ | 96,200 KB |
| 実行使用メモリ | 175,456 KB |
| 最終ジャッジ日時 | 2026-09-01 00:53:39 |
| 合計ジャッジ時間 | 14,383 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
N = int(input())
A = [[*input()] for _ in range(N)]
trie = [dict()]
count = [0]
for a in A:
curr = 0
count[0] += 1
for c in a:
if c in trie[curr]:
to = trie[curr][c]
else:
to = len(trie)
trie.append(dict())
count.append(0)
trie[curr][c] = to
count[to] += 1
curr = to
Q = int(input())
curr = 0
stack = [0]
ans = N
for _ in range(Q):
cmd, *query = input().split()
cmd = int(cmd)
if cmd == 1:
x = query[0]
if x in trie[curr]:
to = trie[curr][x]
else:
to = len(trie)
trie.append(dict())
count.append(0)
trie[curr][x] = to
stack.append(to)
curr = to
elif cmd == 2:
stack.pop()
curr = stack[-1]
else:
print(count[curr])