A. Snacktower

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.

Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.

However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.

Write a program that models the behavior of Ankh-Morpork residents.

Input

The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.

The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.

Output

Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.

Examples
Input
3 
3 1 2
Output
3   

2 1
Input
5 
4 5 1 2 3
Output
  
5 4    
3 2 1
Note

In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.

题目链接:http://codeforces.com/contest/767/problem/A

题意:给出一列数,让你把这个数按照从大到小输出,当然数字必须要连续,并且比他小的数在序列中位置必须要在他前面,比如,给你5个数,那么,你第一个数当然要找5,然后看5所在位置前面有没有4接着往下,如果不等就输出空行。

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
const int N=;
int a[N]={};
int main()
{
int n;
scanf("%d",&n);
int m=n;
for(int i=;i<n;i++)
{
int p;
cin>>p;
a[p]=;////对各个位置数进行标记,实际上在进行着排序
while(a[m]==)
{
printf("%d ",m);
m--;
}
printf("\n");
}
return ;
}

codeforces 767A Snacktower(模拟)的更多相关文章

  1. CodeForces - 767A Snacktower

    题目大意 一个数可以被输出当且仅当所有比它大的数都已经输出.输入一个1~n的排列,求每次输出的输出序列. 题解 直接用堆模拟 #include <queue> #include <c ...

  2. Codeforces Round #398 (Div. 2) A. Snacktower 模拟

    A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...

  3. 【codeforces 767A】Snacktower

    [题目链接]:http://codeforces.com/contest/767/problem/A [题意] 每天掉一个盘子下来;盘子有大小从1..n依次增大n个盘子; 然后让你叠盘子; 最底层为n ...

  4. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  5. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  6. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  7. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  8. Codeforces 679B. Barnicle 模拟

    B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...

  9. CodeForces 382C【模拟】

    活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...

随机推荐

  1. 【二十四】使用mysqli扩展类批量执行多条sql语句

    批量处理多个sql语句 <?php //批量执行多个dml语句 // $mysqli=new mysqli("localhost","root",&quo ...

  2. bzoj 4444: [Scoi2015]国旗计划

    Description A国正在开展一项伟大的计划--国旗计划.这项计划的内容是边防战士手举国旗环绕边境线奔袭一圈.这 项计划需要多名边防战士以接力的形式共同完成,为此,国土安全局已经挑选了N名优秀的 ...

  3. Android破解学习之路(六)——Android游戏 方块冒险 破解

    前言: 可能大家看到标题会有些懵逼,以为我发错了,这应该是五才对吧,其实,五我已经发了,不过被管理大大移出首页了,不知道这一篇是不是也会是同样的命运.. 今天所写的是关于支付宝内购的破解 原版 链接: ...

  4. [编织消息框架][netty源码分析]9 Promise 实现类DefaultPromise职责与实现

    netty Future是基于jdk Future扩展,以监听完成任务触发执行Promise是对Future修改任务数据DefaultPromise是重要的模板类,其它不同类型实现基本是一层简单的包装 ...

  5. C# .net中json字符串和对象之间的转化方法

    http://blog.csdn.net/xuexiaodong009/article/details/46998069 json作为作为一种最常用的数据,应用很广泛,在.net中如何把一个对象转化为 ...

  6. 如何高逼格读取Web.config中的AppSettings

    http://edi.wang/post/2015/4/22/how-to-read-webconfig-appsettings-with-bigiblity 先插句题外话,下版本的ASP.NET貌似 ...

  7. HTML学习 框架

    iframe 在原来的页面嵌入其他页面 <iframe src="其他页面地址" width="宽" height="高" frame ...

  8. nvm 装 nodejs 重启终端失效的解决方法

    (1) 安装 nvm wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash (2) ...

  9. MySQL中各种数据类型的长度及在开发中如何选择

    接触MySQL这个数据库大概快要两年了,不过由于没有特别深入系统的去学习,大多也是停留在一知半解的状态.今天在工作中刚好碰到了表设计的问题,顺便写篇博客,把MySQL中数据类型和字段类型选择这方面给弄 ...

  10. 20 Zabbix系统性能优化建议

    点击返回:自学Zabbix之路 20 Zabbix系统性能优化建议 1. Zabbix性能变慢的可能表现: zabbix队列有太多被延迟的item,可以通过administration-queue查看 ...