思路:
假设从第i首歌开始听,结束位置为j,那么从第i+1首歌开始听,结束位置一定不早于j。可以用反证法证明。想到这一点,就不难解决了。

实现:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int INF = 0x3f3f3f3f;
  4. const int N = ;
  5. int a[N], st[N][];
  6. int log2(int x)
  7. {
  8. int res = -;
  9. while (x) { x >>= ; res++; }
  10. return res;
  11. }
  12. void init(int n)
  13. {
  14. for (int i = ; i < n; i++) st[i][] = a[i];
  15. for (int j = ; ( << j) < n; j++)
  16. {
  17. for (int i = ; i + ( << j) - < n; i++)
  18. {
  19. st[i][j] = max(st[i][j - ], st[i + ( << j - )][j - ]);
  20. }
  21. }
  22. }
  23. int get_max(int l, int r)
  24. {
  25. if (l > r) return -INF;
  26. int p = log2(r - l + );
  27. return max(st[l][p], st[r - ( << p) + ][p]);
  28. }
  29. int main()
  30. {
  31. int n;
  32. while (cin >> n)
  33. {
  34. int minn = INF, maxn = -INF;
  35. for (int i = ; i < n; i++)
  36. {
  37. cin >> a[i]; a[i + n] = a[i + * n] = a[i];
  38. minn = min(a[i], minn);
  39. maxn = max(a[i], maxn);
  40. }
  41. init( * n);
  42. vector<int> res(n, -);
  43. if (maxn <= minn * )
  44. {
  45. for (auto it: res) cout << it << " ";
  46. cout << endl; continue;
  47. }
  48. int cur = ;
  49. for (int i = ; i < n; i++)
  50. {
  51. cur = max(cur, i + );
  52. int maxn = get_max(i, cur);
  53. while (cur < * n && a[cur] * >= maxn)
  54. {
  55. maxn = max(maxn, a[cur]); cur++;
  56. }
  57. res[i] = cur - i;
  58. }
  59. for (auto it: res) cout << it << " ";
  60. cout << endl;
  61. }
  62. return ;
  63. }

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. 原生javascript禁用和屏蔽鼠标右键

    (function(){ var doc=document, ua = navigator.userAgent.toLowerCase(), check = function(r){return r. ...

  2. Neither shaken nor stirred(DFS理解+vector存图)

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2013 题目理解: 给定n个点的有向图: 下面n行,第一个数字表示点权,后面一个数字m表示 ...

  3. day25 内置常用模块(四): 模块和包

    阅读目录: 模块 import from xxx import xxx 包 import from xxx import xxx    from xxx  import *    __init__.p ...

  4. python提取计算结果的最大最小值及其坐标

    我们在fluent当中后处理的时候,可以通过fluent本身得到某些物理量的最大值和最小值,但是我们却无法确定这些最大值和最小值的具体位置.其实我们可以将求解数据导出以后,借助python求得最大值和 ...

  5. Python: 在CSV文件中写入中文字符

    0.2 2016.09.26 11:28* 字数 216 阅读 8053评论 2喜欢 5 最近一段时间的学习中发现,Python基本和中文字符杠上了.如果能把各种编码问题解决了,基本上也算对Pytho ...

  6. 阿里druid连接池监控数据自定义存储

    如何将druid连接池监控到的sql执行效率,连接池资源情况等进行持久化存储,方便系统运维分析优化,以下案例初步测试成功. 第一部: 新建MyDruidStatLogger类实现接口 extends ...

  7. 查看Linux系统的USB设备

    查看Linux系统的USB设备 lsusb (centos没有该命令) dmesg (内核日志会输出) 执行dmesg

  8. CentOS上安装GlassFish4.0

    1.  安装jdk 2. 下载并安装glassfish4 [root@linuxidc ~]# mv glassfish-4.0-ml.zip /usr/share/glassfish-4.0-ml. ...

  9. 解决Wireshark安装Npcap组件失败

    解决Wireshark安装Npcap组件失败   从Wireshark 3.0开始,Npcap取代Winpcap组件,成为Wireshark默认的网卡核心驱动.由于该组件属于驱动程序,所以安装时候容易 ...

  10. Android输入法遮挡了输入框,使用android:fitsSystemWindows="true"后界面顶部出现白条解决方案

    我的最外层是LinearLayout,自定义CustomLinearLayout继承LinearLayout,重写fitSystemWindows和onApplyWindowInsets两个方法: p ...