-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1986C Update Queries.cpp
54 lines (49 loc) · 1.03 KB
/
1986C Update Queries.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Author : MishkatIT
Created : Sunday 23-06-2024 21:09:59
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
using ll = long long;
using ld = long double;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 10;
const ll inf = 1e9;
const ll linf = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
int n, m;
cin >> n >> m;
string str;
cin >> str;
map<int, int> mp;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
mp[x]++;
}
deque<char> c(m);
for (auto& i : c) cin >> i;
sort(c.begin(), c.end());
for (auto& i : mp) {
int cnt = i.second - 1;
while (cnt > 0) {
cnt--;
c.pop_back();
}
str[i.first - 1] = c.front();
c.pop_front();
}
cout << str << '\n';
}
return 0;
}