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 ...
随机推荐
- 原生javascript禁用和屏蔽鼠标右键
(function(){ var doc=document, ua = navigator.userAgent.toLowerCase(), check = function(r){return r. ...
- Neither shaken nor stirred(DFS理解+vector存图)
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2013 题目理解: 给定n个点的有向图: 下面n行,第一个数字表示点权,后面一个数字m表示 ...
- day25 内置常用模块(四): 模块和包
阅读目录: 模块 import from xxx import xxx 包 import from xxx import xxx from xxx import * __init__.p ...
- python提取计算结果的最大最小值及其坐标
我们在fluent当中后处理的时候,可以通过fluent本身得到某些物理量的最大值和最小值,但是我们却无法确定这些最大值和最小值的具体位置.其实我们可以将求解数据导出以后,借助python求得最大值和 ...
- Python: 在CSV文件中写入中文字符
0.2 2016.09.26 11:28* 字数 216 阅读 8053评论 2喜欢 5 最近一段时间的学习中发现,Python基本和中文字符杠上了.如果能把各种编码问题解决了,基本上也算对Pytho ...
- 阿里druid连接池监控数据自定义存储
如何将druid连接池监控到的sql执行效率,连接池资源情况等进行持久化存储,方便系统运维分析优化,以下案例初步测试成功. 第一部: 新建MyDruidStatLogger类实现接口 extends ...
- 查看Linux系统的USB设备
查看Linux系统的USB设备 lsusb (centos没有该命令) dmesg (内核日志会输出) 执行dmesg
- CentOS上安装GlassFish4.0
1. 安装jdk 2. 下载并安装glassfish4 [root@linuxidc ~]# mv glassfish-4.0-ml.zip /usr/share/glassfish-4.0-ml. ...
- 解决Wireshark安装Npcap组件失败
解决Wireshark安装Npcap组件失败 从Wireshark 3.0开始,Npcap取代Winpcap组件,成为Wireshark默认的网卡核心驱动.由于该组件属于驱动程序,所以安装时候容易 ...
- Android输入法遮挡了输入框,使用android:fitsSystemWindows="true"后界面顶部出现白条解决方案
我的最外层是LinearLayout,自定义CustomLinearLayout继承LinearLayout,重写fitSystemWindows和onApplyWindowInsets两个方法: p ...