結果

問題 No.3667 Prefix Count Queries
ユーザー Unbakedbread
提出日時 2026-09-13 22:34:08
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 857 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,081 ms
コンパイル使用メモリ 336,712 KB
実行使用メモリ 32,752 KB
最終ジャッジ日時 2026-09-13 22:34:19
合計ジャッジ時間 9,223 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1 RE * 2
other AC * 8 WA * 3 RE * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

struct Node {
	int p, val;
	array<int, 26> v;
	Node(int p) : p(p), val(0) {memset(v.data(), -1, sizeof(v.data()));}
};

vector<Node> v = {Node(-1)};

int move(int t, char c) {
	const int a = c - 'a';
	if(v[t].v[a] == -1) {
		v[t].v[a] = v.size();
		v.push_back(Node(t));
	}
	return v[t].v[a];
}

void insert(string S) {
	int now = 0;
	v[now].val += 1;
	for(auto c : S) {
		now = move(now, c);
		v[now].val += 1;
	}
}

int main() {
	int N;
	cin >> N;
	vector<string> A(N);
	for(int i = 0; i < N; ++i) cin >> A[i];
	
	for(int i = 0; i < N; ++i) insert(A[i]);
	
	int Q;
	cin >> Q;
	
	int now = 0;
	while(Q--) {
		int cmd;
		cin >> cmd;
		
		if(cmd == 1) {
			char x;
			cin >> x;
			
			now = move(now, x);
		}
		
		if(cmd == 2) {
			now = v[now].p;
		}
		
		if(cmd == 3) {
			cout << v[now].val << "\n";
		}
	}
}
0