結果
| 問題 | No.3667 Prefix Count Queries |
| ユーザー |
|
| 提出日時 | 2026-08-15 20:01:09 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 1,727 ms / 2,000 ms |
| + 435µs | |
| コード長 | 1,227 bytes |
| 記録 | |
| コンパイル時間 | 1,746 ms |
| コンパイル使用メモリ | 208,424 KB |
| 実行使用メモリ | 9,932 KB |
| 最終ジャッジ日時 | 2026-09-01 00:51:02 |
| 合計ジャッジ時間 | 10,607 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
if (!(cin >> N)) return 0;
vector<string> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
// A を辞書順にソート
sort(A.begin(), A.end());
int Q;
cin >> Q;
string S = "";
while (Q--) {
int type;
cin >> type;
if (type == 1) {
char x;
cin >> x;
S.push_back(x);
} else if (type == 2) {
S.pop_back();
} else if (type == 3) {
if (S.empty()) {
cout << N << "\n";
} else {
// S 以上の最小の要素の位置
auto left = lower_bound(A.begin(), A.end(), S);
// S を接頭辞として持つ範囲の右端('z' の次の ASCII 文字 '{' を末尾につけた文字列未満の位置)
string S_upper = S + '{';
auto right = lower_bound(A.begin(), A.end(), S_upper);
cout << (right - left) << "\n";
}
}
}
return 0;
}