沐枫NOI 28. Queue
来源:互联网 发布:高中知识点总结软件 编辑:程序博客网 时间:2024/06/08 10:26
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 ai.
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 ai>aj. 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.
Input
The first line contains an integer n (2≤n≤105) − the number of walruses in the queue. The second line contains integers ai(1≤ai≤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.
Output
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.
Examples
Input
610 8 5 3 50 45
Output
2 1 0 -1 0 -1
Input
710 4 6 3 2 8 15
Output
4 2 1 0 -1 -1 -1
Input
510 3 1 10 11
Output
1 0 -1 -1 -1
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>#include<set>#include<queue>#include<cstring>#include<map>using namespace std;int main(){int a[100000+10];int n;cin>>n;for(int i=n-1;i>=0;i--){scanf("%d",&a[i]);}int out[100000+10];for(int i=0;i<n;i++){int sum=-1;for(int j=0;j<i;j++) if(a[i]>a[j]){sum=i-j-1;break;}out[i]=sum; }for(int i=n-1;i>=0;i--) cout<<out[i]<<" ";return 0;}
- 沐枫NOI 28. Queue
- 沐枫NOI 10. Leaders
- 沐枫NOI 14. Football
- 沐枫NOI 17. Volleyball
- NOI
- 沐枫NOI 21. Restoring Password
- 沐枫NOI 25. Binary Number
- 沐枫NOI 30. African Crossword
- 沐枫NOI 2839. 单词替换
- 28. Queue
- 沐枫NOI 6. Help Chef Gerasim 模拟
- 沐枫NOI 7. Help Far Away Kingdom
- 沐枫NOI 13. Lucky Numbers (easy)
- 沐枫NOI 2838. 删除单词后缀 string
- Queue
- queue
- Queue
- QUEUE ~
- 沐枫NOI 25. Binary Number
- 何为分布式、微服务和集群!
- echo 客户端
- Hibernate中Get和Load的区别
- 不能建立引用数组,数组中的元素不能是引用
- 沐枫NOI 28. Queue
- C#基础知识点(三)
- 001 快速安装Gitlab
- 【Angular2】Information组件设计
- 从键盘输入并显示
- Java并发学习(一)-synchronized及锁的学习
- OpenStack设计与实现读书笔记Chapter 2
- Python入门及安装
- arcgis api for javascript 计算长度和面积