首页 > 其他分享 >Scoring Subsequences

Scoring Subsequences

时间:2023-06-24 09:44:21浏览次数:39  
标签:Scoring sequence int maximum score Subsequences test 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 s1⋅s2⋅…⋅sdd!1⋅2⋅…⋅!, where d!=1⋅2⋅…⋅d!=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 a1≤a2≤…≤an1≤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 (1≤t≤1041≤≤104). The description of the test cases follows.

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

The second line of each test case contains n integers a1,a2,…,an1,2,…, (1≤ai≤n1≤≤) — 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 5⋅1055⋅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;
}

 

标签:Scoring,sequence,int,maximum,score,Subsequences,test,subsequences
From: https://www.cnblogs.com/o-Sakurajimamai-o/p/17500718.html

相关文章

  • 「解题报告」CF1621G Weighted Increasing Subsequences
    比较套路的拆贡献题。考虑直接枚举那个\(j\),求有多少包含\(j\)的上升子序列满足这个子序列最后一个数的后面有大于\(a_j\)的数。首先对于\(j\)前面的选择方案是没有影响的,可以直接拿树状数组DP一遍得到。后面的过程我们可以找到从后往前第一个大于\(a_j\)的数的位置......
  • 1332. Remove Palindromic Subsequences刷题笔记
    容易陷入思维盲区,只有a和b的字符串,只会有2个或1个回文classSolution:defremovePalindromeSub(self,s:str)->int:return2-(s==s[::-1])......
  • GridSearchCV中的scoring
    说明scoring参数输入形式包括字符串、可调用对象或评分函数。以下是常用的评分规则示例:使用预定义的字符串指定评分规则:'accuracy':准确率(分类问题)'precision':精确率(分类问题)'recall':召回率(分类问题)'f1':F1分数(分类问题)'r2':R2分数(回归问题)'mean_squared_error':均方误差(......
  • CF1794C Scoring Subsequences题解
    文中\(a\)为题目中给的\(a\)。如果我们要求\(a_1,a_2,a_3,\dots,a_m\)的结果,那么我们可以把\(a\)数组从后往前依次除以\(i\),\(i\)从\(1\)到\(n\),即为\(\frac{a_1}{m},\frac{a_2}{m-1},\frac{a_3}{m-2},\dots,\frac{a_{m-1}}{2},\frac{a_m}{1}\),并将其保......
  • 「USACO2016JAN」Subsequences Summing to Sevens
    [USACO16JAN]SubsequencesSummingtoSevensS题目描述FarmerJohn's\(N\)cowsarestandinginarow,astheyhaveatendencytodofromtimetotime.EachcowislabeledwithadistinctintegerIDnumbersoFJcantellthemapart.FJwouldliketota......
  • AtCoder Regular Contest 134 D Concatenate Subsequences
    洛谷传送门AtCoder传送门我一年前甚至不会做/qd发现\(a_{x_1}\)为\(k=\min\limits_{i=1}^na_i\)时最优。然后开始分类讨论:如果\(\min\limits_{a_i=k}a_{i+n}\lek\),答案为\((k,\min\limits_{a_i=k}a_{i+n})\)。这是因为如果再选一个\(k\)肯定不优。否则......
  • CF 1368B Codeforces Subsequences
    题目地址题意:给你一个数n,构造一个字符串,使得至少有n个子串为codeforcesSolution用贪心的思想肯定是只在codeforces基础上修改对于每个字符,对答案的贡献都是乘以字符的......
  • Rosetta scoring
    参考:https://www.rosettacommons.org/demos/latest/tutorials/scoring/scoring介绍Rosetta有一个被称为ref2015(默认打分函数)的优化能量函数或打分函数,用于计算由L-氨基酸......
  • [LeetCode] 1332. Remove Palindromic Subsequences 删除回文子序列
    Youaregivenastring s consisting only ofletters 'a' and 'b'.Inasinglestepyoucanremoveone palindromicsubsequence from s.Return the mi......
  • Codeforces Round #661 (Div. 3) D. Binary String To Subsequences(贪心/思维)
    https://codeforces.com/contest/1399/problem/D题目大意:长度为n的字符串s只由0和1组成。我们要把s分成最小数量的子序列,使得每一个子序列看起来像“010101...”或......