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.

 #include <string.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#define maxn 1000005
int a[maxn],b[maxn];
int main()
{
int n;
while((scanf("%d",&n))!=EOF)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
int t=n;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
b[a[i]]=;
for(;b[t]==;t--)
printf("%d ",t);
printf("\n");
}
}
return ;
}

767A Snacktower的更多相关文章

  1. codeforces 767A Snacktower(模拟)

    A. Snacktower time limit per test:2 seconds memory limit per test:256 megabytes input:standard input ...

  2. CodeForces - 767A Snacktower

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

  3. 【codeforces 767A】Snacktower

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

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

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

  5. CF767 A. Snacktower 暴力

    LINK 题意:给出一个序列,如果存的数满足连续递减(第一个必须为n)则输出否则输出空行,并暂存当前数 思路:直接暴力不可行,由于待输出的数的个数满足单调性可以稍微优化,即从上一回输出的最小一个数开始 ...

  6. 【暴力】Codeforces Round #398 (Div. 2) A. Snacktower

    题意不复述. 用个bool数组记录一下,如果某一天,当前剩下的最大的出现了的话,就输出一段. #include<cstdio> using namespace std; int n; bo ...

  7. Codeforces Round #398 (Div. 2)

    Codeforces Round #398 (Div. 2) A.Snacktower 模拟 我和官方题解的命名神相似...$has$ #include <iostream> #inclu ...

  8. Codeforces Round #398 (div.2)简要题解

    这场cf时间特别好,周六下午,于是就打了打(谁叫我永远1800上不去div1) 比以前div2的题目更均衡了,没有太简单和太难的...好像B题难度高了很多,然后卡了很多人. 然后我最后做了四题,E题感 ...

  9. mac环境破解navicat premium 12.1

    1. 下载破解工具 https://github.com/DoubleLabyrinth/navicat-keygen/tree/mac 其中,navicat-keygen为破解器:navicat-p ...

随机推荐

  1. 网络基础知识 tcp

    网络基础相关的知识(1)架构a. C / S架构: client客户端和server服务器端 优势: 能充分发挥PC机的性能b. B / S架构: browser浏览器和server服务器 隶属于C ...

  2. 进度条 --- socket ---socketserver

    TCP:可靠的面向连接的协议,传输效率低,全双工通信,流数据传输.运用:web浏览器,电子邮件,文件传输程序 UDP:不可靠的,无连接的服务,传输效率高,面向数据包的传输,只能发短消息.运用:dns ...

  3. 3.1_分类算法之k-近邻

    分类算法之k-近邻 k-近邻算法采用测量不同特征值之间的距离来进行分类 优点:精度高.对异常值不敏感.无数据输入假定 缺点:计算复杂度高.空间复杂度高 使用数据范围:数值型和标称型 一个例子弄懂k-近 ...

  4. jap -文档 https://www.tutorialspoint.com/jpa/jpa_jpql.htm

    参考网址:https://www.tutorialspoint.com/jpa/jpa_jpql.htm

  5. JS转义解码方法

    之前只知道可以解决传值乱码问题,今天刚好看到,从新补充下: JavaScript中有三个可以对字符串编码的函数,分别是: 转义方法: escape();//函数可对字符串进行编码 encodeURI( ...

  6. maven的小知识

    一.下载及安装 1.1 下载maven 3.1.1 先到官网http://maven.apache.org/download.cgi 下载最新版本(目前是3.1.1 ),下载完成后,解压到某个目录(本 ...

  7. HTTPS 路径配置

    1: 首先安装 fiddlercertmaker.exe 文件   2:Tools  -> HTTPS    3: Connections 勾中Allow remote computer to ...

  8. linux控制台批量杀进程

    -| cd /app/tomcat8/bin/ ./startup.sh

  9. C++实现ping功能<转>

    今天接到需求要实现ping的功能,然后网上查了一些资料,对网络编程的一些函数熟悉了一下,虽然还有一些细节不清楚,但是慢慢积累. 要实现这样的功能: 基础知识 ping的过程是向目的IP发送一个type ...

  10. LaiFeng-code

    https://github.com/LaiFeng-Android/SopCastComponent https://github.com/LaiFengiOS/