Precreation contest files
This commit is contained in:
56
misc/hsg-hp-2025/cbai4.cpp
Normal file
56
misc/hsg-hp-2025/cbai4.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void solve() {
|
||||
vector<deque<int>> char_pos(26);
|
||||
|
||||
int n, q;
|
||||
string S;
|
||||
cin >> n >> q >> S;
|
||||
|
||||
vector<int> is_exist(n, 1);
|
||||
set<int> exist_char;
|
||||
|
||||
// O(n)
|
||||
for (int i = 0; i < n; i++) {
|
||||
char_pos[S[i] - 'A'].push_back(i);
|
||||
}
|
||||
|
||||
// O(1)
|
||||
for (int i = 0; i < 26; i++)
|
||||
if (!char_pos[i].empty())
|
||||
exist_char.insert(i);
|
||||
|
||||
while (q--) {
|
||||
if (exist_char.empty())
|
||||
break;
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
int target_char;
|
||||
if (t == 0)
|
||||
target_char = *exist_char.begin();
|
||||
else
|
||||
target_char = *exist_char.rbegin();
|
||||
|
||||
int target_idx = char_pos[target_char].front();
|
||||
char_pos[target_char].pop_front();
|
||||
is_exist[target_idx] = 0;
|
||||
|
||||
if (char_pos[target_char].empty())
|
||||
exist_char.erase(target_char);
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
if (is_exist[i])
|
||||
cout << S[i];
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
solve();
|
||||
}
|
||||
Reference in New Issue
Block a user