CF1622B.Berland Music
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Berland Music is a music streaming service built specifically to support Berland local artist. Its developers are currently working on a song recommendation module.
So imagine Monocarp got recommended n songs, numbered from 1 to n . The i -th song had its predicted rating equal to pi , where 1≤pi≤n and every integer from 1 to n appears exactly once. In other words, p is a permutation.
After listening to each of them, Monocarp pressed either a like or a dislike button. Let his vote sequence be represented with a string s , such that si=0 means that he disliked the i -th song, and si=1 means that he liked it.
Now the service has to re-evaluate the song ratings in such a way that:
- the new ratings q1,q2,…,qn still form a permutation ( 1≤qi≤n ; each integer from 1 to n appears exactly once);
- every song that Monocarp liked should have a greater rating than every song that Monocarp disliked (formally, for all i,j such that si=1 and sj=0 , qi>qj should hold).
Among all valid permutations q find the one that has the smallest value of i=1∑n∣pi−qi∣ , where ∣x∣ is an absolute value of x .
Print the permutation q1,q2,…,qn . If there are multiple answers, you can print any of them.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of testcases.
The first line of each testcase contains a single integer n ( 1≤n≤2⋅105 ) — the number of songs.
The second line of each testcase contains n integers p1,p2,…,pn ( 1≤pi≤n ) — the permutation of the predicted ratings.
The third line contains a single string s , consisting of n characters. Each character is either a 0 or a 1 . 0 means that Monocarp disliked the song, and 1 means that he liked it.
The sum of n over all testcases doesn't exceed 2⋅105 .
输出格式
For each testcase, print a permutation q — the re-evaluated ratings of the songs. If there are multiple answers such that i=1∑n∣pi−qi∣ is minimum possible, you can print any of them.
输入输出样例
输入#1
3 2 1 2 10 3 3 1 2 111 8 2 3 1 8 5 4 7 6 01110001
输出#1
2 1 3 1 2 1 6 5 8 3 2 4 7
说明/提示
In the first testcase, there exists only one permutation q such that each liked song is rating higher than each disliked song: song 1 gets rating 2 and song 2 gets rating 1 . i=1∑n∣pi−qi∣=∣1−2∣+∣2−1∣=2 .
In the second testcase, Monocarp liked all songs, so all permutations could work. The permutation with the minimum sum of absolute differences is the permutation equal to p . Its cost is 0 .