给出一个小写字母字符串,现在有m种魔法,每种魔法可以将区间LR的字母变为新字母X,求最后字符串的最大字典序。
两种比较容易想到的操作:
#include <bits/stdc++.h>
using namespace std;const int N = 1e7 + 5;char s[N];
struct node
{int l, r;char f[2];bool operator<(const node &temp) const { return f[0] > temp.f[0]; }
} op[N];int fa[N];int find(int x)
{if (x == fa[x])return x;return fa[x] = find(fa[x]);
}
void solve()
{int n, m;scanf("%d %d", &n, &m);for (int i = 1; i <= n + 1; i++)fa[i] = i;scanf("%s", s + 1);for (int i = 1; i <= m; i++)scanf("%d %d %s", &op[i].l, &op[i].r, op[i].f);sort(op + 1, op + 1 + m);for (int i = 1; i <= m; i++){for (int j = op[i].l; j <= op[i].r; j = find(j + 1)){// cout << 't' << j << endl;s[j] = max(s[j], op[i].f[0]);fa[j] = j + 1;}}int ans = 0;for (int i = 1; i <= n; i++)ans += s[i];printf("%dn", ans);
}int main()
{solve();return 0;
}
本文发布于:2024-02-05 09:22:55,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170728637665265.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |