Ice and Fire

Ice and Fire
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Little09 and his friends are playing a game. There are n players, and the temperature value of the player i is i.

The types of environment are expressed as 00 or 11. When two players fight in a specific environment, if its type is 00, the player with a lower temperature value in this environment always wins; if it is 11, the player with a higher temperature value in this environment always wins. The types of the n1−1 environments form a binary string s with a length of n1−1.

If there are x players participating in the game, there will be a total of x1−1 battles, and the types of the x1−1 environments will be the first x1−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 si.

For each x from 22 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?

Input

Each test contains multiple test cases. The first line contains a single integer t (1t1031≤≤103)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (2n21052≤≤2⋅105)  — the number of players.

The second line of each test case contains a binary string s with a length n1−1.

It is guaranteed that the sum of n over all test cases does not exceed 31053⋅105.

Output

For each test case output n1−1 integers  — for each x from 22 to n, output the number of players that have a chance to win.

Example
input
Copy
2
4
001
4
101
output
Copy
1 1 3 1 2 3
Note

In the first test case, for x=2=2 and x=3=3, only the player whose temperature value is 11 can be the winner. For x=4=4, the player whose temperature value is 2,3,42,3,4 can be the winner.

#include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n>>s; int one=0,zero=0,res=1; for(int i=0;i<s.size();i++){ if(s[i]=='1') one++,zero=0; else one=0,zero++; cout<<i+2-max(one,zero)<<" "; } } return 0; }

 


__EOF__

本文作者Sakurajimamai
本文链接https://www.cnblogs.com/o-Sakurajimamai-o/p/17572945.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   o-Sakurajimamai-o  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
-- --
点击右上角即可分享
微信分享提示