思路:
假设从第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. HTTP文件上传

    看到网上很多链接文件(word.pdf...)可以下载,想制作http下载链接. 其实是将某文件直接放在服务器上搭建的网站上某目录下即可,例如:http://xxx:port/UpgradePack/ ...

  2. 2-STM32+W5500+GPRS物联网开发基础篇-基础篇学习的内容

    https://www.cnblogs.com/yangfengwu/p/10936553.html 这次的基础篇为公开篇,将公开所有基础篇的资料和源码 现在说一下基础篇准备公开的内容:(大部分哈,要 ...

  3. noi.ac #30 思维

    \(des\) 给定升序数组 \(A, B\) 对于任意两个集合 \(a, b\) 分别是 \(A, B\) 的子集,总价值为较小的集合的和, 总代价为 \((|a| + |b|) \times w\ ...

  4. 使用flexmark将MarkDown转为HTML

    引入对应的依赖 <!-- https://mvnrepository.com/artifact/com.vladsch.flexmark/flexmark --> <dependen ...

  5. python3之线程(一)

    线程的概念 现在的操作系统几乎都支持运行多个任务,而在操作系统内部,一个任务往往代表的执行的某一个程序,也就是运行中的程序,运行的程序是一个动态的概念,也就是所说的进程,而在进程内部,往往有许多顺序执 ...

  6. Spring源码之XmlBeanDefinitionReader与Resource

    一.DefaultListableBeanFactory类, 里面有一个成员变量beanDefinitionMap,Bean定义对象的Map, BeanDefinition就对应XML的属性配置 /* ...

  7. 使用HttpClient访问WebHook

    代码: import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.c ...

  8. 制作 python解释器

    https://www.zhihu.com/tardis/sogou/qus/27286136

  9. MySQL not equal to operator <> && !=

    MySQL :: MySQL 5.7 Reference Manual :: 12.3.2 Comparison Functions and Operatorshttps://dev.mysql.co ...

  10. matplotlib实战

    plt.imshow(face_image.mean(axis=2),cmap='gray') 图片灰度处理¶   size = (m,n,3) 图片的一般形式就是这样的 rgb 0-255 jpg图 ...