Codeforces Round #710 (Div. 3) G. Maximize the Remaining String
用单调栈维护拿的字母即可
const int maxn = 1e3 + 7;
int n, t, m, cnt[300];
string s;
void solve() {
cin >> t;
while (t--) {
memset(cnt, 0, sizeof cnt);
cin >> s;
for (auto c:s) cnt[c]++;
string ans;
for (auto c:s) {
cnt[c]--;
if (ans.find(c) != -1) continue;
while (ans.size() && cnt[ans.back()] && ans.back() < c) ans.pop_back();
ans.push_back(c);
}
cout << ans << endl;
}
}
我看见 你