A8261 | Queue
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains an integer $n$ ( $2<=n<=10^{5}$ ) — the number of walruses in the queue. The second line contains integers $a_{i}$ ( $1<=a_{i}<=10^{9}$ ).
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.
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.
输出格式
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.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted