Seg-El has last chance to make the final changes in order to prevent the destruction of Krypton.

He is provided an array Arr[ ] of N elements.

For each element Arr [ i ], he needs to find the largest element Arr [ j ] where j < i and Arr [ j ] < Arr [ i ]

Help him to achieve this task.

Input

First line comprises N- the number of elements in the array.

Second line contains N space separated integers denoting the elements of the array.

Output

Print N lines denoting the required answer as specified above. In case no such value exists for some

Arr [ i ], print "-1" (without quotes).

Constraints

  • 1 ≤ N ≤ 200000
  • 1 ≤ Arr [ i ] ≤ 1015

Example


1 2 3 5 4

Output:

-1 



3

通过 set 或 map 就可轻松解决;

关键字 :  set ,map ,  lower_bound()函数

1.学长的代码

 # include <bits/stdc++.h>
using namespace std;
set<long long> s;
int main ()
{
int n;
long long x;
scanf("%d", &n);
for (int i = ; i <= n; ++i) {
scanf("%lld", &x);
x = -x;
auto iter = s.lower_bound(x + );
if (iter == s.end()) puts("-1");
else printf("%lld\n", -*iter);
s.insert(x);
}
return ;
}

2 . 一开始不会使用set ,用map自己做的

 #include<bits/stdc++.h>
using namespace std;
int main()
{
map<long long,int> imap;
long long t;
int n;
cin>>n;
for(int i =;i<=n;i++)
{
scanf("%lld",&t);
t = -t;
//map<long long,int>::iterator it;
auto it = imap.lower_bound(t+);
if(it == imap.end()) cout<<"-1"<<endl;
else
cout<<-(it->first)<<endl;
imap[t] = i;
}
return ;
}

最新文章

  1. 女生的最爱,装饰品。WPF也有,Adorner。(上海晒衣服理念)
  2. [moka同学摘录]SQL内联、外联的简单理解
  3. jquery实现页面交互的几个小例子
  4. JS中取整以及随机颜色问题
  5. oracle触发器及异常处理 简单例子
  6. Docker CPU 资源限制——CPU固定核功能测试
  7. 【学习笔记】【C语言】类型说明符
  8. 24种设计模式--工厂方法模式【Factory Method Pattern】
  9. CODEVS 1287 矩阵乘法
  10. laravel框架中所用到的依赖注入
  11. EF Core学习Code First
  12. 如何设置织梦cms自定义表单字段为必填项
  13. docker中安装ps命令
  14. mysql 开发基础系列5 运算符
  15. IIS 错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
  16. css 可继承属性 display:inline-block 历史
  17. 3--Selenium环境准备--Eclipse 引入 selenium-server包
  18. WEBapi在IIS发布注意事项-发布错误
  19. SQL Server 用角色(Role)管理数据库权限
  20. IT小鲜肉 Widgets Tree 单选、多选、相关回调函数、获取选中的节点功能

热门文章

  1. 用Android studio进行 OpenCV 开发的第一个项目
  2. BizMDM企业主数据管理平台
  3. VS2015卸载方法
  4. web service 对外发布一个hello world接口(入门)
  5. linux挂载和卸载NAS操作
  6. Makedown语法说明
  7. 关于安卓手机访问一些网站或者Fiori应用弹出安装证书的提示
  8. 页面文本超出后CSS实现隐藏的方法
  9. C#自定义规则对比两个集合的对象是否相等
  10. Spring Boot的Maven插件Spring Boot Maven plugin详解