🐨 | CF1898E
考虑没有排序操作的情况:枚举
现在加入了排序,发现一段字符排序之后是不可逆的,所以我们尽量保证每次匹配操作后
每个字符的出现位置用队列维护,时间复杂度
const int maxn = 2e5 + 10;
int n, m; char s[maxn], t[maxn]; queue<int> q[26];
void work() {
n = read(), m = read();
scanf("%s %s", s + 1, t + 1);
for (int i = 0; i < 26; i ++) while (!q[i].empty()) q[i].pop();
for (int i = 1; i <= n; i ++) q[s[i] - 'a'].push(i);
for (int i = 1; i <= m; i ++) {
int c = t[i] - 'a', id;
if (q[c].empty()) return printf("NO\n"), void();
id = q[c].front(), q[c].pop();
for (int j = 0; j < c; j ++)
while (!q[j].empty() && q[j].front() < id) q[j].pop();
}
printf("YES\n");
}