CF91B.Queue

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to a__i.

The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that a__i > a__j. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.

The airport manager asked you to count for each of n walruses in the queue his displeasure.

有 nn 头海象在机场排成一队。它们从队尾开始编号:第 11 头海象位于队尾,第 nn 头海象位于队首。第 ii 头海象的年龄为 aia_i。

当第 ii 头海象前方(即队列中编号更大的位置)存在比它更年轻的海象时,它会感到不悦;也就是说,若存在某个 jj(满足 i<ji < j)使得 ai>aja_i > a_j,则第 ii 头海象不悦。第 ii 头海象的不悦程度定义为:在它与它前方最远的一个比它更年轻的海象之间所夹的海象数量。换言之,那个更年轻的海象离它越远,它的不悦程度就越强。

机场经理要求你对队列中的每头海象(共 nn 头),分别计算其不悦程度。

输入格式

The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers a__i (1 ≤ a__i ≤ 109).

Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one.

第一行包含一个整数 nn(2≤n≤1052 \leq n \leq 10^5)—— 队列中海象的数量。第二行包含整数 aia_i(1≤ai≤1091 \leq a_i \leq 10^9)。

注意:某些海象的年龄可能相同,但要使不满情绪产生,队列中更靠近队首的海象的年龄必须严格小于另一只海象的年龄。

输出格式

Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus.

输出 n 个数字:如果第 i 头海象对一切都很满意,则输出 -1(不带引号);否则,输出第 i 头海象的不满值:即在他与离他最远的、比他更年轻的海象之间所夹的其他海象的数量。

输入输出样例

  • 输入#1

    6
    10 8 5 3 50 45

    输出#1

    2 1 0 -1 0 -1
  • 输入#2

    7
    10 4 6 3 2 8 15

    输出#2

    4 2 1 0 -1 -1 -1
  • 输入#3

    5
    10 3 1 10 11

    输出#3

    1 0 -1 -1 -1

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

首页