1774C.md (2156B)
1 Source: https://codeforces.com/problemset/problem/1774/C 2 3 C. Ice and Fire 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Little09 and his friends are playing a game. There are $n$ players, and the temperature value of the player $i$ is $i$. 22 23 The types of environment are expressed as $0$ or $1$. When two players fight in a specific environment, if its type is $0$, the player with a lower temperature value in this environment always wins; if it is $1$, the player with a higher temperature value in this environment always wins. The types of the $n-1$ environments form a binary string $s$ with a length of $n-1$. 24 25 If there are $x$ players participating in the game, there will be a total of $x-1$ battles, and the types of the $x-1$ environments will be the first $x-1$ characters of $s$. While there is more than one player left in the tournament, choose any two remaining players to fight. The player who loses will be eliminated from the tournament. The type of the environment of battle $i$ is $s_i$. 26 27 For each $x$ from $2$ to $n$, answer the following question: if all players whose temperature value does not exceed $x$ participate in the game, how many players have a chance to win? 28 29 Input 30 31 Each test contains multiple test cases. The first line contains a single integer $t$ ($1\le t \le 10^3$) — the number of test cases. The description of the test cases follows. 32 33 The first line of each test case contains a single integer $n$ ($2\leq n\leq 2\cdot 10^5$) — the number of players. 34 35 The second line of each test case contains a binary string $s$ with a length $n-1$. 36 37 It is guaranteed that the sum of $n$ over all test cases does not exceed $3\cdot 10^5$. 38 39 Output 40 41 For each test case output $n-1$ integers — for each $x$ from $2$ to $n$, output the number of players that have a chance to win. 42 43 Example 44 45 Input 46 47 ``` 48 2 49 50 4 51 52 001 53 54 4 55 56 101 57 ``` 58 59 Output 60 61 ``` 62 1 1 3 63 1 2 3 64 ``` 65 66 Note 67 68 In the first test case, for $x=2$ and $x=3$, only the player whose temperature value is $1$ can be the winner. For $x=4$, the player whose temperature value is $2,3,4$ can be the winner.