CF1237D Balanced Playlist
思路:
假设从第i首歌开始听,结束位置为j,那么从第i+1首歌开始听,结束位置一定不早于j。可以用反证法证明。想到这一点,就不难解决了。
实现:
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = ;
int a[N], st[N][];
int log2(int x)
{
int res = -;
while (x) { x >>= ; res++; }
return res;
}
void init(int n)
{
for (int i = ; i < n; i++) st[i][] = a[i];
for (int j = ; ( << j) < n; j++)
{
for (int i = ; i + ( << j) - < n; i++)
{
st[i][j] = max(st[i][j - ], st[i + ( << j - )][j - ]);
}
}
}
int get_max(int l, int r)
{
if (l > r) return -INF;
int p = log2(r - l + );
return max(st[l][p], st[r - ( << p) + ][p]);
}
int main()
{
int n;
while (cin >> n)
{
int minn = INF, maxn = -INF;
for (int i = ; i < n; i++)
{
cin >> a[i]; a[i + n] = a[i + * n] = a[i];
minn = min(a[i], minn);
maxn = max(a[i], maxn);
}
init( * n);
vector<int> res(n, -);
if (maxn <= minn * )
{
for (auto it: res) cout << it << " ";
cout << endl; continue;
}
int cur = ;
for (int i = ; i < n; i++)
{
cur = max(cur, i + );
int maxn = get_max(i, cur);
while (cur < * n && a[cur] * >= maxn)
{
maxn = max(maxn, a[cur]); cur++;
}
res[i] = cur - i;
}
for (auto it: res) cout << it << " ";
cout << endl;
}
return ;
}
CF1237D Balanced Playlist的更多相关文章
- 并不对劲的CF1237D&E:Balanced Playlist and Binary Search Trees
CF1237D Balanced Playlist 题意 有一个长度为\(n\)(\(n\leq 10^5\))的循环播放歌单,每首歌有一个优秀值\(a_i\)(\(a_i\leq 10^9\)). ...
- 【CF1237D】Balanced Playlist(set,二分,线段树)
题意:给定一个n首歌的播放列表,第i首的值为a[i],听完第i首会回到第1首 现在从每首开始往下,记录听过的最大值,如果当前听的值严格小于听过最大值的一半则停止 问从每首歌开始往下听能听几首,不会停止 ...
- Codeforces 1237D. Balanced Playlist
传送门 首先显然的,如果一个位置开始播放了两圈还没结束,那么就永远不会结束 先考虑位置 $1$ 开始播放,用一个 $multisetset$ 维护一下当前听的所有歌,直到某一首歌 $r$ 不合法了就停 ...
- Codeforces Global Round 5
传送门 A. Balanced Rating Changes 签到,分正负搞一下就行. B. Balanced Tunnel 题意: 给出\(n\)辆车的进洞顺序和出洞顺序,问有多少量车实现了洞中超车 ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- CCI4.4/LintCode Balanced Binary Tree, Binary Tree, Binary Search Tree
Binary Tree: 0到2个子节点; Binary Search Tree: 所有左边的子节点 < node自身 < 所有右边的子节点: 1. Full类型: 除最下面一层外, 每一 ...
- 110.Balanced Binary Tree Leetcode解题笔记
110.Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...
- [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- LeetCode - Balanced Binary Tree
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...
随机推荐
- 【Redis】Linux下Redis的安装
Redis服务安装 主要有两种方式:apt安装和编译安装. 我采用的是apt安装,系统是ubuntu18.04,Redis version 5:4.0.9-1 在 Ubuntu 系统安装 Redi 可 ...
- /etc/shells
List of acceptable shells for chpass(1). Ftpd will not allow users to connect who are not using one ...
- Ubuntu下面删除和卸载软件
1.卸载nginx 1)首先执行第一条命令查出想关的软件包: dpkg --get-selections | grep nginx 2)开始执行卸载列出的common 和core 这个2个安装包 一个 ...
- 洛谷 P1230 智力大冲浪 题解
P1230 智力大冲浪 题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者 \(m\)元.先不要太高兴!因为这些钱还不一定都是你的 ...
- AtCoder Grand Contest 017题解
传送门 \(A\) 直接转移就是了 typedef long long ll; const int N=55; ll f[N][2];int a[N],n,p; int main(){ scanf(& ...
- Linux使用logrotate定时分割日志
1.分割nginx日志vim /etc/logrotate.d/nginx/var/log/nginx/*log { create 0644 nginx nginx rotate 10 missing ...
- C# 使用大漠插件, 源码在Github和码云 ..希望对大家有所帮助
c# 使用大漠插件. 完成 类似 按键精灵的 功能. 方法 注释 正在慢慢的 完善中 目录 仓库 github 码云 准备 效果图 如何运行 1. 注册 大漠dll 到com (资源在 源码 DLL ...
- windows下的上帝模式,很好用,细想,很恐怖啊
原文地址:https://blog.csdn.net/qq_43371556/article/details/101210501 上帝模式,即"God Mode”,或称为“完全控制面板”.是 ...
- SpringMVC从Request域中获取数据
SpringMVC从Request域中获取数据的三种方式 SpringMVC环境自行搭建, 约定存在如下目录和文件:/WEB-INF/pages/success.jsp 方式一:传入Model对象 前 ...
- mysql使用replace和on duplicate key update区别
实际业务使用中,有时候会遇到插入数据库,但是如果某个属性(比如:主键)存在,就做更新.通常有两种方式:1.replace into 2.on duplicate key update 但是在使用过程 ...