You are given an integer array of length nn.

You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x,x+1,…,x+k−1][x,x+1,…,x+k−1] for some value xx and length kk.

Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array [5,3,1,2,4][5,3,1,2,4] the following arrays are subsequences: [3][3], [5,3,1,2,4][5,3,1,2,4], [5,1,4][5,1,4], but the array [1,3][1,3] is not.

Input

The first line of the input containing integer number nn (1≤n≤2⋅1051≤n≤2⋅105) — the length of the array. The second line of the input containing nn integer numbers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the array itself.

Output

On the first line print kk — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.

On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.

Examples

Input
7
3 3 4 7 5 6 8
Output
4
2 3 5 6
Input
6
1 3 5 2 4 6
Output
2
1 4
Input
4
10 9 8 7
Output
1
1
Input
9
6 7 8 3 4 5 9 10 11
Output
6
1 2 3 7 8 9

Note

All valid answers for the first example (as sequences of indices):

  • [1,3,5,6][1,3,5,6]
  • [2,3,5,6][2,3,5,6]

All valid answers for the second example:

  • [1,4][1,4]
  • [2,5][2,5]
  • [3,6][3,6]

All valid answers for the third example:

  • [1][1]
  • [2][2]
  • [3][3]
  • [4][4]

All valid answers for the fourth example:

  • [1,2,3,7,8,9]

题目大意:

先输入n,然后输入n个数,然后找最长递增子串,输出各个元素的下标。

#include <bits/stdc++.h>
using namespace std;
int a[];
map <int,int> ma;
int main()
{
int n;
cin>>n;
for(int i=,x;i<=n;i++)
cin>>x,a[i]=x,ma[x]=ma[x-]+;
int pos,maxx=;
for(map <int,int>::iterator it=ma.begin();it!=ma.end();it++)
{
if(it->second>maxx)
maxx=it->second,pos=it->first;
}
cout<<maxx<<'\n';
for(int i=;i<=n;i++)
if(a[i]==pos-maxx+)
cout<<i<<' ',pos++;
cout<<'\n';
return ;
}

Consecutive Subsequence (DP+map)的更多相关文章

  1. 【UVa】Palindromic Subsequence(dp+字典序)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=465&page=s ...

  2. CodeForces - 1000D:Yet Another Problem On a Subsequence (DP+组合数)

    The sequence of integers a1,a2,…,aka1,a2,…,ak is called a good array if a1=k−1a1=k−1 and a1>0a1&g ...

  3. POJ 2533 Longest Ordered Subsequence(dp LIS)

    Language: Default Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  4. HDU1423 Greatest Common Increasing Subsequence (DP优化)

    LIS和LCS的结合. 容易写出方程,复杂度是nm2,但我们可以去掉一层没有必要的枚举,用一个变量val记录前一阶段的最优解,这样优化成nm. 1<=k<j,j增加1,k的上界也增加1,就 ...

  5. 【Unity Shader】六、使用法线贴图(Normal Map)的Shader

    学习资料: http://www.sikiedu.com/course/37/task/456/show# http://www.sikiedu.com/course/37/task/458/show ...

  6. 取数字(dp优化)

    取数字(dp优化) 给定n个整数\(a_i\),你需要从中选取若干个数,使得它们的和是m的倍数.问有多少种方案.有多个询问,每次询问一个的m对应的答案. \(1\le n\le 200000,1\le ...

  7. 洛谷P2507 [SCOI2008]配对 题解(dp+贪心)

    洛谷P2507 [SCOI2008]配对 题解(dp+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1299251 链接题目地址:洛谷P2507 [S ...

  8. [Codeforces722E] Research Rover (dp+组合数学)

    [Codeforces722E] Research Rover (dp+组合数学) 题面 给出一个N*M的方格阵,从(1,1)出发,到(N,M)结束,从(x,y)只能走到(x+1,y)或(x,y+1) ...

  9. Mybatis(万能map)

    mybatis(万能map) 我们使用对象作为参数有一个缺点: 我们要在mapper.xml文件和测试中要把所有的字段都写出来,那么,假如一个对象有100个字段,那我们要把这些字段都写出来吗? 所以这 ...

随机推荐

  1. mongodb备份、还原

    1.mongodb  备份 mongodump 命令可以使用可用的选项的列表. 此命令将仅备份指定的数据库,在指定的路径 语法 描述 示例 mongodump --host HOST_NAME --p ...

  2. Wrapper class package.jaxws.methodName is not found. Have you run APT to generate them?解决方案

    使用JAX-WS 2.X基于Web容器发布WebService报错,错误信息类似于: Wrapper class package.jaxws.methodName is not found. Have ...

  3. Objective-C Protocols

    Objective-C allows you to define protocols, which declare the methods expected to be used for a part ...

  4. Obj-C Memory Management

    Memory management is one of the most important process in any programming language. It is the proces ...

  5. 项目经验——jboss 配置数据库连接池

    数据库的连接和关闭是非常消耗系统资源的,在多层结构的应用环境中,这种资源消耗又直接的反映到系统性能上来.在项目实际应用中,最常用的解决方案便是建立数据库连接池. 一.数据库连接池基本原理 当程序启动时 ...

  6. springmvc+maven搭建web项目

    1.创建一个maven project 为spring1 2.进行项目的配置:默认的java 1.5 在properties中选择project facts项目进行配置,反选web之后修改java环境 ...

  7. The Django Book - 第四章 模板2

    模板(相应)使用的几种方式: 1.使用HttpResponse返回字符串HTML from django.http import HttpResponse def current_datetime(r ...

  8. GUI进化--数据与界面分离

    http://blog.csdn.net/doon/article/details/5946862 1.何谓数据和界面分离? GUI,即Graphic User Interface,人机交换界面.连接 ...

  9. 栈的应用——Rails

    一.题目描述 某城市有一个火车站,有n节车厢从A方向驶入车站,按进站顺序编号为1~n,经中转站C驶向B.中转站C,这是一个可以停放任意多节车厢的车站,但由于末端封顶,驶入C的车厢必须以相反的顺序驶出C ...

  10. smarty 运算符列表

    下面是可用的运算符列表,使用中都会放到元素的中间并且用空格分隔. 注意列表中[方括号]的是可选的,而且还会列出对应PHP的表达式. 详见:Chapter 7. 内置函数 运算符 别名 语法示例 含义 ...