Precreation contest files

This commit is contained in:
2026-02-11 11:28:23 +07:00
parent 0a8ea477bb
commit cb9f7cab30
134 changed files with 1848 additions and 0 deletions

View 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();
}