#include <bits/stdc++.h>
using namespace std;
int a[1000006];
int b[1000006];
int sta[100006];
int main()
{
int t,n,i,j,top;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%d",&n);
for( i = 1; i <= n; i ++)
{
scanf("%d", &a[i]);
}
top = 0;
b[n] = -1;
for(i = n - 1; i >= 1; i --)
{
if(a[i + 1] > a[i])
{
b[i] = a[i + 1];
sta[top ++] = b[i];
// cout << "sta[top] = "<< sta[top - 1] << endl;
}
else {
int f = 1;
while(top)
{
// cout << "top = " <<top << endl;
if(sta[top - 1] > a[i])
{
b[i] = sta[top - 1];
f = 0;
break;
}
top --;
}
if(top == 0 || f == 1) b[i] = -1;
}
}
for(i = 1; i <= n; i ++)
{
printf("%d-->%d\n",a[i],b[i]);
}
if(t != 0) printf("\n");
} }
return 0;
}

最新文章

  1. 并查集+树链剖分+线段树 HDOJ 5458 Stability(稳定性)
  2. 关于Memo或者Edit之类控件, 直接设置Text无法撤销的解决方案
  3. Java基础之一组有用的类——使用公历日历(TryCalendar)
  4. 简单实用的纯CSS百分比圆形进度条插件
  5. Apache模块 mod_proxy 转自http://www.php100.com/manual/apache2/mod/mod_proxy.html
  6. 001. 为input type=text 时设置默认值
  7. MVC中前台如何向后台传递数据------$.get(),$post(),$ajax(),$.getJSON()总结
  8. SaaS系列介绍之十二: SaaS产品的研发模式
  9. btn控件
  10. Error message “Assembly must be registered in isolation” when registering Plugins in Microsoft Dynamics CRM 2011 2013 解决办法
  11. Python开发【第二十二篇】:Web框架之Django【进阶】
  12. .Net 4.0 Convert Object to XDocument
  13. bootstrap之 Badge 角标
  14. PHP中将对数据库的操作,封装成一个工具类以及学会使用面向对象的方式进行编程
  15. 深度学习工具caffe具体安装指南
  16. Ext.Net 使用总结之GridPanel中的选中行
  17. Web程序和应用程序服务器[转]
  18. [leetcode-560-Subarray Sum Equals K]
  19. 历年NOIP选题题解汇总
  20. 【unix网络编程第三版】ubuntu端口占用问题

热门文章

  1. SQL优化中的重要概念:锁定
  2. Asp.Net Core Linux环境下 找不到配置文件、静态文件的问题
  3. python实现nc
  4. ThinkPHP5.0.*远程代码执行漏洞预警
  5. Python中的内存管理机制
  6. springboot2.0介绍1
  7. 利用jenkens+github实现简单的CI/CD
  8. 解决yum命令后出现libldap-2.4.so.2: cannot open shared object file
  9. MySQL全同步复制基于GR集群架构实现(Centos7)
  10. Linux服务器TIME_WAIT进程的解决与原因