CF1927 B. Following the String
给定长度为
n 的序列a 。你需要构造一个长度为n 的仅由小写字母构成的字符串s ,满足对于所有的i ,a_i = \sum_{j = 1}^{i - 1}[s_i = s_j] 。多测。
t \le 10^4 ,\sum n \le 2 \times 10^5 ,0 \le a_i < n ,保证有解。
模拟。
维护一个桶
然后更新桶往后计算即可。
void solve() {
int n = read();
vector<int> a(n);
string s = "";
vector<int> t(200);
for (int &c : a) {
c = read();
fup (i, 'a', 'z') {
if (t[i] == c) {
++ t[i];
s.push_back(i);
break;
}
}
}
cout << s << '\n';
return;
}