Scoring Subsequences

Scoring Subsequences
time limit per test
2.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The score of a sequence [s1,s2,,sd][1,2,…,] is defined as s1s2sdd!1⋅2⋅…⋅!, where d!=12d!=1⋅2⋅…⋅. In particular, the score of an empty sequence is 11.

For a sequence [s1,s2,,sd][1,2,…,], let m be the maximum score among all its subsequences. Its cost is defined as the maximum length of a subsequence with a score of m.

You are given a non-decreasing sequence [a1,a2,,an][1,2,…,] of integers of length n. In other words, the condition a1a2an1≤2≤…≤ is satisfied. For each k=1,2,,n=1,2,…,, find the cost of the sequence [a1,a2,,ak][1,2,…,].

A sequence x is a subsequence of a sequence y if x can be obtained from y by deletion of several (possibly, zero or all) elements.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t1041≤≤104). The description of the test cases follows.

The first line of each test case contains an integer n (1n1051≤≤105) — the length of the given sequence.

The second line of each test case contains n integers a1,a2,,an1,2,…, (1ain1≤≤) — the given sequence. It is guaranteed that its elements are in non-decreasing order.

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

Output

For each test case, output n integers — the costs of sequences [a1,a2,,ak][1,2,…,] in ascending order of k.

Example
input
Copy
3
3
1 2 3
2
1 1
5
5 5 5 5 5
output
Copy
1 1 2 1 1 1 2 3 4 5
Note

In the first test case:

  • The maximum score among the subsequences of [1][1] is 11. The subsequences [1][1] and [][] (the empty sequence) are the only ones with this score. Thus, the cost of [1][1] is 11.
  • The maximum score among the subsequences of [1,2][1,2] is 22. The only subsequence with this score is [2][2]. Thus, the cost of [1,2][1,2] is 11.
  • The maximum score among the subsequences of [1,2,3][1,2,3] is 33. The subsequences [2,3][2,3] and [3][3] are the only ones with this score. Thus, the cost of [1,2,3][1,2,3] is 22.
Therefore, the answer to this case is 112112, which are the costs of [1],[1,2][1],[1,2] and [1,2,3][1,2,3] in this order.
复制代码
#include <bits/stdc++.h> //#define int long long using namespace std; const int N=1e5+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans; bool vis[N]; int op(int u) { if(u==1||u==0) return 1; return u*op(u-1); } int main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n; res=0; for(int i=1;i<=n;i++){ cin>>a[i]; int l=1,r=i; //如果当前的数小于长度,那就肯定到不了最大值,所以求最小的当前值能让序列价值达到最大 //二分即可 while(l<r){ int mid=l+r>>1; if(a[mid]>=i-mid+1) r=mid; else l=mid+1; } cout<<i-l+1<<" "; } cout<<endl; } return 0; }
复制代码

 


__EOF__

本文作者Sakurajimamai
本文链接https://www.cnblogs.com/o-Sakurajimamai-o/p/17500718.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   o-Sakurajimamai-o  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
-- --
点击右上角即可分享
微信分享提示