思路:
假设从第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 ;
}

最新文章

  1. 基于opencv和mfc的摄像头采集代码(GOMFCTemplate2)
  2. mave的变量说明
  3. checkbox与jq&lt;转&gt;2
  4. 在ASP.NET非MVC环境中(WebForm中)构造MVC的URL参数
  5. [转]C# List&lt;T&gt;的详细用法
  6. Cisco基本命令配置
  7. 求给定数据中最小的K个数
  8. ruby条件控制结构
  9. antlr v4 使用指南连载1——简介
  10. .NET Core实战项目之CMS 第六章 入门篇-Vue的快速入门及其使用
  11. SQL 日期时间比较
  12. ros中自定义消息 报错 ImportError: No module named em
  13. HTTP请求处理流程 MVC核心(MVC就是扩展了一个HttpModule)
  14. centos7之安装wordpress
  15. bzoj4709 柠檬 单调栈,DP,斜率优化
  16. C++设计模式 ==&gt; 装饰(者)模式
  17. windows下,怎么轻易拷贝一个文件的完整路径?
  18. 【Alpha 冲刺】 5/12
  19. distinct group by
  20. 基于Unity3d 引擎的Android游戏优化

热门文章

  1. CF463D Gargari and Permutations dp
  2. PHP安装mysql.so扩展及相关PHP.ini 配置参数说明
  3. Cogs 376. [IOI2002]任务安排(后效性DP)
  4. 机器学习实战(1)- KNN
  5. FCS省选模拟赛 Day4
  6. select下拉框多选取值
  7. Flutter扫码识别二维码内容
  8. html5中time元素详解
  9. cropper手机使用实例
  10. make 实例 一 3463