Sakurako's Hobby
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Problem
For a certain permutation Sakurako calls an integer reachable from an integer if it is possible to make equal to by assigning a certain number of times.
If then, for example, is reachable from because: Now so is reachablefrom
Each number in the permutation is colored either black or white.
Sakurako defines the function as the number of black integers that are reachable from
Sakurako is interested in for each but calculating all values becomes very difficult, so she asks you, as her good friend, to compute this.
permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation (the number appears twice in the array), and is also not a permutation ( but the array contains ).
Input
The first line contains a single integer — the number of test cases.
The first line of each test case contains a single integer — the number of elements in the array.
The second line of each test case contains integers — the elements of the permutation.
The third line of each test case contains a string of length consisting of '0' and '1'. If then the number is colored black; if then the number is colored white.
It is guaranteed that the sum of across all test cases does not exceed .
Output
For each test case, output integers
Example : in
5
1
1
0
5
1 2 4 5 3
10101
5
5 4 1 3 2
10011
6
3 5 6 1 2 4
010000
6
1 2 3 4 5 6
100110
Example : out
1
0 1 1 1 1
2 2 2 2 2
4 1 4 4 1 4
0 1 1 0 0 1
语法基础(数组、字符串及数据批量存储)+ 压力
- 状态
- 已结束
- 规则
- ACM/ICPC
- 题目
- 6
- 开始于
- 2024-10-11 19:00
- 结束于
- 2024-10-12 0:00
- 持续时间
- 5 小时
- 主持人
- 参赛人数
- 7