CF1622B.Berland Music

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

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 nn songs, numbered from 11 to nn. The ii-th song had its predicted rating equal to pip_i, where 1≤pi≤n1 \le p_i \le n and every integer from 11 to nn appears exactly once. In other words, pp 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 ss, such that si=0s_i=0 means that he disliked the ii-th song, and si=1s_i=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,…,qnq_1, q_2, \dots, q_n still form a permutation (1≤qi≤n1 \le q_i \le n; each integer from 11 to nn appears exactly once);
  • every song that Monocarp liked should have a greater rating than every song that Monocarp disliked (formally, for all i,ji, j such that si=1s_i=1 and sj=0s_j=0, qi>qjq_i \gt q_j should hold).

Among all valid permutations qq find the one that has the smallest value of ∑i=1n∣pi−qi∣\sum\limits_{i=1}^n |p_i-q_i|, where ∣x∣|x| is an absolute value of xx.

Print the permutation q1,q2,…,qnq_1, q_2, \dots, q_n. If there are multiple answers, you can print any of them.

Berland Music 是一项专为支持 Berland 本地艺术家而打造的音乐流媒体服务。其开发人员目前正在开发一个歌曲推荐模块。

假设 Monocarp 被推荐了 nn 首歌曲,编号从 11 到 nn。第 ii 首歌曲的预测评分为 pip_i,其中 1≤pi≤n1 \le p_i \le n,且 11 到 nn 中的每个整数恰好出现一次。换言之,pp 是一个排列。

在听完每首歌曲后,Monocarp 要么点击“喜欢”,要么点击“不喜欢”。设他的投票序列为字符串 ss,其中 si=0s_i = 0 表示他不喜欢第 ii 首歌曲,si=1s_i = 1 表示他喜欢该歌曲。

现在,该服务需重新评估歌曲评分,使得:

  • 新的评分 q1,q2,…,qnq_1, q_2, \dots, q_n 仍构成一个排列(即 1≤qi≤n1 \le q_i \le n,且 11 到 nn 中的每个整数恰好出现一次);
  • Monocarp 喜欢的每首歌曲的评分必须严格大于他不喜欢的每首歌曲的评分(形式化地,对所有满足 si=1s_i = 1 和 sj=0s_j = 0 的 i,ji, j,均有 qi>qjq_i > q_j)。

在所有满足条件的排列 qq 中,找出使 ∑i=1n∣pi−qi∣\sum\limits_{i=1}^n |p_i - q_i| 最小的那个(其中 ∣x∣|x| 表示 xx 的绝对值)。

输出排列 q1,q2,…,qnq_1, q_2, \dots, q_n。若存在多个答案,输出任意一个即可。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

The first line of each testcase contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of songs.

The second line of each testcase contains nn integers p1,p2,…,pnp_1, p_2, \dots, p_n (1≤pi≤n1 \le p_i \le n) — the permutation of the predicted ratings.

The third line contains a single string ss, consisting of nn characters. Each character is either a 00 or a 11. 00 means that Monocarp disliked the song, and 11 means that he liked it.

The sum of nn over all testcases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)——歌曲的数量。

每个测试用例的第二行包含 nn 个整数 p1,p2,…,pnp_1, p_2, \dots, p_n(1≤pi≤n1 \le p_i \le n)——预测评分的一个排列。

第三行包含一个长度为 nn 的字符串 ss,其中每个字符为 00 或 11。00 表示 Monocarp 不喜欢该歌曲,11 表示他喜欢该歌曲。

所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each testcase, print a permutation qq — the re-evaluated ratings of the songs. If there are multiple answers such that ∑i=1n∣pi−qi∣\sum\limits_{i=1}^n |p_i-q_i| is minimum possible, you can print any of them.

对于每个测试用例,输出一个排列 qq —— 歌曲重新评估后的评分。如果存在多个满足 ∑i=1n∣pi−qi∣\sum\limits_{i=1}^n |p_i-q_i| 为最小可能值的答案,你可以输出其中任意一个。

输入输出样例

  • 输入#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 qq such that each liked song is rating higher than each disliked song: song 11 gets rating 22 and song 22 gets rating 11. ∑i=1n∣pi−qi∣=∣1−2∣+∣2−1∣=2\sum\limits_{i=1}^n |p_i-q_i|=|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 pp. Its cost is 00.

在第一个测试用例中,仅存在一个排列 qq,使得每个喜欢的歌曲的评分均高于每个不喜欢的歌曲:歌曲 11 的评分为 22,歌曲 22 的评分为 11。∑i=1n∣pi−qi∣=∣1−2∣+∣2−1∣=2\sum\limits_{i=1}^n |p_i-q_i|=|1-2|+|2-1|=2。

在第二个测试用例中,Monocarp 喜欢所有歌曲,因此所有排列均满足条件。绝对差之和最小的排列即为与 pp 相同的排列,其代价为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页