文中 \(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}\),并将其保存在数组 \(s\) 中。

因为 \(a_1 \leq a_2 \leq a_3 \leq \dots \leq a_m\),且 \(\frac{1}{i}\) 单调递增,所以 \(s_1 \leq s_2 \leq s_3 \dots \leq s_m\)。

那么我们自然而然地可以想到,每一次的结果就是末尾的几个数字的乘积(因为 \(s\) 越大越好),即 \(s_k \times s_{k + 1} \times \dots \times s_m\)。

那么 \(k\) 取多少呢?

我们只取对自己有利的部分,所以当 \(s_k \geq 1\) 且 \(s_{k - 1} < 1\) 时,我们可以达到最大值 \(ans = s_k \times s_{k + 1} \times \dots \times s_m\)。

因为 \(s\) 单调不下降,所以可以使用二分来得出要保留的数字 \(m - k\)。

对每一个 \(m\) 进行操作,\(1 \leq m \leq n\)。

时间复杂度:\(O(n \log n)\)。

C++代码

/*******************************
| Author: SunnyYuan
| Problem: C. Scoring Subsequences
| Contest: Codeforces Round 856 (Div. 2)
| URL: https://codeforc.es/contest/1794/problem/C
| When: 2023-03-06 08:30:32
|
| Memory: 256 MB
| Time: 2500 ms
*******************************/ #include <iostream>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; const int N = 100010; int n, a[N]; void solve() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) {
int l = -1, r = i + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (a[i - mid + 1] >= mid) l = mid;
else r = mid;
}
cout << l << ' ';
}
cout << '\n';
} int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) solve(); return 0;
}

CF1794C Scoring Subsequences题解的更多相关文章

  1. Codeforces Round #674 (Div. 3) F. Number of Subsequences 题解(dp)

    题目链接 题目大意 给你一个长为d只包含字符'a','b','c','?' 的字符串,?可以变成a,b,c字符,假如有x个?字符,那么有\(3^x\)个字符串,求所有字符串种子序列包含多少个abc子序 ...

  2. CodeForces 689 D Friends and Subsequences

    Friends and Subsequences 题解: 如果左端点来说, 那么对于a[i]来说是向上的一条折线, b[i]来说是向下的一条折线, 那么如果这2个折线求交点个数的话, 我们可以二分去求 ...

  3. 算法与数据结构基础 - 深度优先搜索(DFS)

    DFS基础 深度优先搜索(Depth First Search)是一种搜索思路,相比广度优先搜索(BFS),DFS对每一个分枝路径深入到不能再深入为止,其应用于树/图的遍历.嵌套关系处理.回溯等,可以 ...

  4. [LeetCode]题解(python):115-Distinct Subsequences

    题目来源: https://leetcode.com/problems/distinct-subsequences/ 题意分析: 给定字符串S和T,判断S中可以组成多少个T,T是S的子串. 题目思路: ...

  5. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  6. CodeForces 689D Friends and Subsequences (RMQ+二分)

    Friends and Subsequences 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/H Description Mi ...

  7. Codeforces Testing Round #12 C. Subsequences 树状数组维护DP

    C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  8. 115. Distinct Subsequences

    题目: Given a string S and a string T, count the number of distinct subsequences of T in S. A subseque ...

  9. HDU 2227 Find the nondecreasing subsequences(DP)

    Problem Description How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3 ...

  10. LeetCode之“动态规划”:Distinct Subsequences

    题目链接 题目要求: Given a string S and a string T, count the number of distinct subsequences of T in S. A s ...

随机推荐

  1. Redis 日志showlog 和 管道pileline

    redis日志 slowlog-log-slower-than:指定执行时间超过多少微秒(1秒等于1000000微秒) 的命令请求会被记录到日志上 slowlog-max-len:指定服务器最多保存多 ...

  2. Java并发(二)----初次使用多线程并行提高效率

    1.并行 并行代表充分利用多核 cpu 的优势,提高运行效率. 想象下面的场景,执行 3 个计算,最后将计算结果汇总. 计算 1 花费 10 ms ​ 计算 2 花费 11 ms ​ 计算 3 花费 ...

  3. 详解C++中的extern与static关键字

    本章通过问答方式明晰两个关键字及其作用. Q1:对于int x:,不加extern关键字他就是个未赋初值的定义,但是如果加了static或者extern都可以表示这仅是一个声明吗? A:不是的,具体情 ...

  4. 轻量级Web框架Flask(二)

    Flask-SQLAlchemy MySQL是免费开源软件,大家可以自行搜索其官网(https://www.MySQL.com/downloads/) 测试MySQL是否安装成功 在所有程序中,找到M ...

  5. JS执行机制--同步与异步

    单线程JavaScript语言具有单线程的特点,同一个时间只能做一件事情.这是因为JavaScript脚本语言是为了处理页面中用户的交互,以及操作DOM而诞生的.如果对某个DOM元素进行添加和删除,不 ...

  6. ROS动态调试PID参数

    ROS动态调试PID参数 连接小车 注意:必须在同一区域网 ssh clbrobort@clbrobort 激活树莓派主板 roslaunch clbrobot bringup.launch 打开PI ...

  7. RK3568用户自定义开机画面功能

    RK方案中的开机画面处画逻辑 在RK的方案中,如RK1109,RK1126,RK3568这些嵌入式LINUX方案在开机画面的处理逻辑都是一致的. 用户的uboot,kernel开机画面都是同dts,k ...

  8. 数据结构(DataStructure)-03

    数据结构-03 **数据结构-03笔记** **递归** **二叉树** **广度遍历 - 二叉树** **深度遍历 - 二叉树** **二叉树练习一** **二叉树练习二** **二叉排序树练习一* ...

  9. Spring源码:bean的生命周期(一)

    前言 本节将正式介绍Spring源码细节,将讲解Bean生命周期.请注意,虽然我们不希望过于繁琐地理解Spring源码,但也不要认为Spring源码很简单.在本节中,我们将主要讲解Spring 5.3 ...

  10. DataX更换python3,File “datax.py“, line 114 print readerRef

    datax 报错 File "datax.py", line 114 print readerRef 报错: File "datax.py", line 114 ...