Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.

For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:

  1. He looks through all the coins from left to right;
  2. If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.

Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.

Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.

The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.

Input

The first line contains single integer n (1 ≤ n ≤ 300 000) — number of coins that Sasha puts behind Dima.

Second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p1, then coin located at position p2 and so on. Coins are numbered from left to right.

Output

Print n + 1 numbers a0, a1, ..., an, where a0 is a hardness of ordering at the beginning, a1 is a hardness of ordering after the first replacement and so on.

Examples
input

Copy
4
1 3 4 2
output

Copy
1 2 3 2 1
input

Copy
8
6 8 3 4 7 2 1 5
output

Copy
1 2 2 3 4 3 4 5 1
Note

Let's denote as O coin out of circulation, and as X — coin is circulation.

At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.

After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.

XOOO  →  OOOX

After replacement of the third coin, Dima's actions look this way:

XOXO  →  OXOX  →  OOXX

After replacement of the fourth coin, Dima's actions look this way:

XOXX  →  OXXX

Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.

理解题意题

https://blog.csdn.net/w326159487/article/details/78255875

 #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + ;
int p[maxn], vis[maxn], n;
int main() {
scanf("%d", &n);
for (int i = ; i < n ; i++) scanf("%d", &p[i]);
int sum = , last = n;
printf("");
for (int i = ; i < n ; i++) {
vis[p[i]] = ;
sum++;
while(vis[last]) sum--, last--;
printf(" %d", sum + );
}
printf("\n");
return ;
}

最新文章

  1. 【转】浏览器内核、渲染引擎、js引擎
  2. Web前端的学习介绍(截止今天还有Bootstrap没有学,要腾点时间解决掉)
  3. 1.6.7 Detecting Languages During Indexing
  4. TCP/IP协议原理与应用笔记25:网际协议(IP)之 数据报(Datagram)
  5. bzoj3790
  6. Two kinds of Quaternion SlerpImp (Unity)
  7. c++之命名空间namespace
  8. EF一次请求公用一个实例
  9. openwrt 串口无法登陆
  10. 【jsp/servlet】 javaweb中的一些简单问题整理
  11. YII 1.0 (7) 登录信息调取 session使用
  12. 在IIS上部署你的ASP.NET Core 2.1项目
  13. 廖雪峰Java9正则表达式-1正则表达式入门-1正则表达式简介
  14. Oracle课程档案,第八天
  15. 物体检测算法 SSD 的训练和测试
  16. 大数据量 与 UI交互时的处理 总结与心得
  17. js,javascript,获取地址栏参数
  18. Freemarker-2.3.22 Demo - No03_使用map绑定多个参数
  19. Phonegap中插件管理
  20. C关系运算结果及逻辑运算结果保存

热门文章

  1. jmeter测试报告优化
  2. 二维数组快速排序(sort+qsort)
  3. UVA10474 Where is the Marble?【排序】
  4. react-router 4.0中跳转失灵
  5. jsp中的input
  6. SQL Server中2008及以上 ldf 文件过大的解决方法
  7. 【Keras案例学习】 sklearn包装器使用示范(mnist_sklearn_wrapper)
  8. NO5——素数筛选
  9. [译]在SQL查询中如何映射(替换)查询的结果?
  10. python 调用RESTFul接口