欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1986C.Update Queries
Update Queries
Let's consider the following simple problem. You are given a string of length , consisting of lowercase Latin letters, as well as an array of indices of length () and a string of length , consisting of lowercase Latin letters. Then, in order, you perform the update operations, namely, during the -th operation, you set . Note that you perform all operations from the first to the last.
Of course, if you change the order of indices in the array and/or the order of letters in the string , you can get different results. Find the lexicographically smallest string that can be obtained after update operations, if you can rearrange the indices in the array and the letters in the string as you like.
A string is lexicographically less than a string if and only if one of the following conditions is met:
- is a prefix of , but ;
- in the first position where and differ, the symbol in string is earlier in the alphabet than the corresponding symbol in string .
Input
Each test consists of several sets of input data. The first line contains a single integer () — the number of sets of input data. Then follows their description.
The first line of each set of input data contains two integers and () — the length of the string and the number of updates.
The second line of each set of input data contains a string of length , consisting of lowercase Latin letters.
The third line of each set of input data contains integers () — the array of indices .
The fourth line of each set of input data contains a string of length , consisting of lowercase Latin letters.
It is guaranteed that the sum of over all sets of input data does not exceed . Similarly, the sum of over all sets of input data does not exceed .
Output
For each set of input data, output the lexicographically smallest string that can be obtained by rearranging the indices in the array and the letters in the string as you like.
Note
In the first set of input data, you can leave the array and the string unchanged and simply perform all operations in that order.
In the second set of input data, you can set the array and "zczw". Then the string will change as follows: $meow \rightarrow zeow \rightarrow ceow \rightarrow ceoz \rightarrow cwoz$.
In the third set of input data, you can leave the array unchanged and set "admn". Then the string will change as follows: $abacaba \rightarrow abacaba \rightarrow abdcaba \rightarrow abdcmba \rightarrow abdcmbn$.
Samples
4
1 2
a
1 1
cb
4 4
meow
1 2 1 4
zcwz
7 4
abacaba
1 3 5 7
damn
7 10
traktor
7 6 5 4 3 2 1 6 4 2
codeforces
b
cwoz
abdcmbn
ccdeefo
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |