思路:
假设从第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的更多相关文章

  1. 并不对劲的CF1237D&E:Balanced Playlist and Binary Search Trees

    CF1237D Balanced Playlist 题意 有一个长度为\(n\)(\(n\leq 10^5\))的循环播放歌单,每首歌有一个优秀值\(a_i\)(\(a_i\leq 10^9\)). ...

  2. 【CF1237D】Balanced Playlist(set,二分,线段树)

    题意:给定一个n首歌的播放列表,第i首的值为a[i],听完第i首会回到第1首 现在从每首开始往下,记录听过的最大值,如果当前听的值严格小于听过最大值的一半则停止 问从每首歌开始往下听能听几首,不会停止 ...

  3. Codeforces 1237D. Balanced Playlist

    传送门 首先显然的,如果一个位置开始播放了两圈还没结束,那么就永远不会结束 先考虑位置 $1$ 开始播放,用一个 $multisetset$ 维护一下当前听的所有歌,直到某一首歌 $r$ 不合法了就停 ...

  4. Codeforces Global Round 5

    传送门 A. Balanced Rating Changes 签到,分正负搞一下就行. B. Balanced Tunnel 题意: 给出\(n\)辆车的进洞顺序和出洞顺序,问有多少量车实现了洞中超车 ...

  5. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  6. CCI4.4/LintCode Balanced Binary Tree, Binary Tree, Binary Search Tree

    Binary Tree: 0到2个子节点; Binary Search Tree: 所有左边的子节点 < node自身 < 所有右边的子节点: 1. Full类型: 除最下面一层外, 每一 ...

  7. 110.Balanced Binary Tree Leetcode解题笔记

    110.Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...

  8. [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 ...

  9. LeetCode - Balanced Binary Tree

    题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...

随机推荐

  1. am335x system upgrade kernel usb stroage(十)

    1      Scope of Document This document describes USB hardware design, support stardard usb2.0 port o ...

  2. 猴猴的比赛 dfs序

    猴猴的比赛 dfs序 两颗\(n\)节点的树,不相同,问多少点对\((u,v)\)在两棵树上均满足路径\(v\)在\(u\)子树中 \(n\le 10^5\) 暴力: \(n^2\)暴力枚举点对用\( ...

  3. Poj 3233 Matrix Power Series(矩阵乘法)

    Matrix Power Series Time Limit: 3000MS Memory Limit: 131072K Description Given a n × n matrix A and ...

  4. Cogs 2546. 取石块儿(博弈)

    取石块儿 ★ 输入文件:tstones.in 输出文件:tstones.out 简单对比 时间限制:1 s 内存限制:256 MB 问题描述 小L和小T进行取石块儿游戏,给定一个整数n表示石块儿总数, ...

  5. 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(& ...

  6. golang 无缓冲channel

    golang 无缓冲channel package main import "fmt" func main() { // 1S =1000ms //1ms = 1000us //1 ...

  7. JSP迭代标签

    1. 新建LoopTag类,代码如下: package bid.zhazhapan.fims.tag; import java.io.IOException; import java.util.Col ...

  8. Ubuntu16.04启动tomcat缓慢问题之解决方案

    问题信息: -May- ::] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of Secur ...

  9. mysql 使用的三个小技巧

    mysql 使用的三个小技巧 快速阅读 Mysql查询工具中如何查询多条语名,Mysql中如何设置变量,Mysql中如何查特定字段,后面再加* Mysql查询工具中如何查询多条语名 默认myslq只能 ...

  10. Spark(四十八):Spark MetricsSystem信息收集过程分析

    MetricsSystem信息收集过程 参考: <Apache Spark源码走读之21 -- WEB UI和Metrics初始化及数据更新过程分析> <Spark Metrics配 ...