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 ...
随机推荐
- am335x system upgrade kernel ec20 simcom7600ce(十一)
1 Scope of Document This document describes 4G hardware design, support quectel ec20 4G module/ ...
- Matlab画图的输出格式
利用Matlab命令,可以输出.eps, .pdf格式的图形.有时候,在图形窗口直接保存会导致图形不完整,这时,可以用如下命令代替: saveas(p1, 't1.eps'); saveas(p1, ...
- CLion201914 下载安装
链接:https://pan.baidu.com/s/12Gzo8gL3iUFoL5wok6L_BQ 密码:7vw4 56ZS5PQ1RF-eyJsaWNlbnNlSWQiOiI1NlpTNVBRM ...
- IDEA中常用快捷键
Alt+Enter 牛掰的万能快捷键,实现接口和抽象类.导入包.异常捕获.转换lambda表达式.equals的翻转和更换访问修饰符等,无所不能. Ctrl+D 复制当前行 Ctrl+Y 删除行 ...
- Java GUI小程序--画板
画板效果 (以前写在Csdn上的博文,没去水印,Csdn名字同博客园) 布局类: package gary; import java.awt.Color; import java.awt.even ...
- html转图片/html2canvas的使用/星座测试/类似于损友圈的活动
https://try.fishqc.com/Activity/constellation ---成品 电脑上录的gif 有借鉴的链接,很多,下面这个还不错~先别看,尊重下我先~~~~ https:/ ...
- Anaconda3自带jupyter
1.cmd命令行中输入 JupyterNotebook 2.系统自动调起下面页面(注册端口冲突是打不开的)
- Authentication failure. Retrying - 彻底解决vagrant up时警告
碰到的问题 使用vagrant启动虚拟机时,出现如下警告: vagrant up default: Warning: Authentication failure. Retrying... 原因分析 ...
- JVM 初始化阶段的重要意义分析
1.创建一个Mytest6类和Singleton类 public class MyTest6 { public static void main(String[] args) { Singleton ...
- exp/imp 注释乱码问题或Oracle EXP-00091的解决方法
今天用imp 导入后,发现中注释乱码,源端.目的端数据库版本都是11.2.0.1 查看源端字符集: SQL> select userenv('language') from dual;USERE ...