CF1237D.Balanced Playlist

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Your favorite music streaming platform has formed a perfectly balanced playlist exclusively for you. The playlist consists of nn tracks numbered from 11 to nn. The playlist is automatic and cyclic: whenever track ii finishes playing, track i+1i+1 starts playing automatically; after track nn goes track 11.

For each track ii, you have estimated its coolness aia_i. The higher aia_i is, the cooler track ii is.

Every morning, you choose a track. The playlist then starts playing from this track in its usual cyclic fashion. At any moment, you remember the maximum coolness xx of already played tracks. Once you hear that a track with coolness strictly less than x2\frac{x}{2} (no rounding) starts playing, you turn off the music immediately to keep yourself in a good mood.

For each track ii, find out how many tracks you will listen to before turning off the music if you start your morning with track ii, or determine that you will never turn the music off. Note that if you listen to the same track several times, every time must be counted.

你最喜爱的音乐流媒体平台为你精心打造了一个完全平衡的播放列表。该播放列表包含 nn 首编号为 11 到 nn 的歌曲。播放列表是自动且循环的:每当第 ii 首歌曲播放完毕,第 i+1i+1 首歌曲便会自动开始播放;在第 nn 首歌曲之后,将再次播放第 11 首歌曲。

对于每首歌曲 ii,你已估算出它的“酷度” aia_i。aia_i 越大,表示第 ii 首歌曲越酷。

每天早晨,你选择一首歌曲作为起点。随后播放列表便从该歌曲开始,按上述循环方式持续播放。在任意时刻,你都会记住已播放过的所有歌曲中的最大酷度 xx。一旦你听到一首酷度严格小于 x2\frac{x}{2}(不四舍五入)的歌曲开始播放,你便会立即关闭音乐,以保持好心情。

对每首歌曲 ii,请计算:若你从第 ii 首歌曲开始一天的播放,你将在关闭音乐前共听到多少首歌曲?若你永远不会关闭音乐,则输出该情况。注意:若同一首歌曲被多次播放,每次均需单独计数。

输入格式

The first line contains a single integer nn (2≤n≤1052 \le n \le 10^5), denoting the number of tracks in the playlist.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9), denoting coolnesses of the tracks.

第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5),表示播放列表中音轨的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9),表示各音轨的酷炫值。

输出格式

Output nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n, where cic_i is either the number of tracks you will listen to if you start listening from track ii or −1-1 if you will be listening to music indefinitely.

输出 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n,其中 cic_i 表示从第 ii 首曲目开始收听时,你将收听的曲目数量;若你将无限地收听音乐,则 ci=−1c_i = -1。

输入输出样例

  • 输入#1

    4
    11 5 2 7

    输出#1

    1 1 3 2
  • 输入#2

    4
    3 2 5 3

    输出#2

    5 4 3 6
  • 输入#3

    3
    4 3 6

    输出#3

    -1 -1 -1

说明/提示

In the first example, here is what will happen if you start with...

  • track 11: listen to track 11, stop as a2<a12a_2 \lt \frac{a_1}{2}.
  • track 22: listen to track 22, stop as a3<a22a_3 \lt \frac{a_2}{2}.
  • track 33: listen to track 33, listen to track 44, listen to track 11, stop as a2<max⁡(a3,a4,a1)2a_2 \lt \frac{\max(a_3, a_4, a_1)}{2}.
  • track 44: listen to track 44, listen to track 11, stop as a2<max⁡(a4,a1)2a_2 \lt \frac{\max(a_4, a_1)}{2}.

In the second example, if you start with track 44, you will listen to track 44, listen to track 11, listen to track 22, listen to track 33, listen to track 44 again, listen to track 11 again, and stop as a2<max(a4,a1,a2,a3,a4,a1)2a_2 \lt \frac{max(a_4, a_1, a_2, a_3, a_4, a_1)}{2}. Note that both track 11 and track 44 are counted twice towards the result.

在第一个例子中,若从以下曲目开始,将发生如下情况:

  • 曲目 11:收听曲目 11,然后停止,因为 a2<a12a_2 \lt \frac{a_1}{2}。
  • 曲目 22:收听曲目 22,然后停止,因为 a3<a22a_3 \lt \frac{a_2}{2}。
  • 曲目 33:收听曲目 33,接着收听曲目 44,再收听曲目 11,然后停止,因为 a2<max⁡(a3,a4,a1)2a_2 \lt \frac{\max(a_3, a_4, a_1)}{2}。
  • 曲目 44:收听曲目 44,接着收听曲目 11,然后停止,因为 a2<max⁡(a4,a1)2a_2 \lt \frac{\max(a_4, a_1)}{2}。

在第二个例子中,若从曲目 44 开始,你将依次收听曲目 44、曲目 11、曲目 22、曲目 33、曲目 44(再次)、曲目 11(再次),然后停止,因为 a2<max⁡(a4,a1,a2,a3,a4,a1)2a_2 \lt \frac{\max(a_4, a_1, a_2, a_3, a_4, a_1)}{2}。注意,曲目 11 和曲目 44 在结果中均被计数两次。

输入解题思路,AI测评打分。不知道怎么写?

首页