【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度。
用f[i]和f[i-1]+1来转移即可

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)2e5;
static class Task{ int n;
HashMap<Integer,Integer> dic = new HashMap<Integer,Integer>();
int a[] = new int[N+10];
ArrayList<Integer> v = new ArrayList<Integer>(); public void solve(InputReader in,PrintWriter out) {
n = in.nextInt();
int len = 0,idx = -1;
for (int i = 1;i <= n;i++) {
a[i] = in.nextInt();
int x = a[i];
if (dic.containsKey(x)) {
int cur = dic.get(x);
int temp = 0;
if (dic.containsKey(x-1)) {
temp = dic.get(x-1);
}
cur = Math.max(cur, temp+1);
dic.put(x, cur);
}else {
int temp = 0;
if (dic.containsKey(x-1)) {
temp = dic.get(x-1);
}
dic.put(x, temp+1);
}
int temp0 = dic.get(x);
if (temp0>len) {
len = temp0;
idx = i;
}
}
out.println(len);
int now = a[idx];
for (int i = idx;i >= 1;i--) {
if (a[i]==now) {
v.add(i);
now--;
}
}
for (int i = (int)v.size()-1;i >= 0;i--) {
out.print(v.get(i)+" ");
} }
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 977F】Consecutive Subsequence的更多相关文章

  1. 【Codeforces 632D】 Longest Subsequence

    [题目链接] 点击打开链接 [算法] 设取的所有数都是k的约数,则这些数的lcm必然不大于k. 对于[1, m]中的每个数,统计a中有多少个数是它的约数即可. [代码] #include<bit ...

  2. 【29.41%】【codeforces 724D】Dense Subsequence

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 750E】New Year and Old Subsequence

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【33.10%】【codeforces 604C】Alternative Thinking

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【32.22%】【codeforces 602B】Approximating a Constant Range

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【38.02%】【codeforces 625B】War of the Corporations

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

随机推荐

  1. bzoj 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛【dp】

    写了个bfs发现MLE了... 设f[t][i][j]为在t时刻走到(i,j)的方案数,转移和bfs一样 #include<iostream> #include<cstdio> ...

  2. 慕课网2-5 编程练习:通过jQuery通配符选择器进行文字变色

    2-5 编程练习 请请使用*选择器将div标签中的字体颜色变成红色 效果图: 任务 (1)使用通配符选择器 (2)使用jQuery的.css()方法设置样式,语法css('属性 '属性值') 参考代码 ...

  3. LOJ#510. 「LibreOJ NOI Round #1」北校门外的回忆(线段树)

    题面 传送门 题解 感谢\(@M\_sea\)的代码我总算看懂题解了-- 这个操作的本质就是每次把\(x\)的\(k\)进制最低位乘\(2\)并进位,根据基本同余芝士如果\(k\)是奇数那么最低位永远 ...

  4. map Codeforces Round #Pi (Div. 2) C. Geometric Progression

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

  5. Android 性能优化(7)网络优化( 3) Optimizing User-Initiated Network Use

    Optimizing User-Initiated Network Use This lesson teaches you to Pre-fetch Network Data Check for Co ...

  6. vue+elementUI table篇

    1.table内容展示 <el-table stripe :key='tableKey' header-cell-class-name="bindonce" :data=&q ...

  7. Android开发: 关于性能需要考虑的

    刚做Android开发时,只管完成任务,将需求完成,以能完成一款界面酷炫的app为自豪.然而,随着代码量的增加,越来越意识到,一款成功的移动端产品,光有酷炫的外衣还不够,还需要在各方面都优秀. 试想, ...

  8. HP M177打印机驱动安装问题与解决

    问题描述 采购HP Color LaserJet Pro MFP M177 PCLmS一台,采用局域网WIFI网络与办公室各电脑连接.安装打印机自带光盘驱动,发现有些电脑安装驱动失败,提示“出现严重错 ...

  9. Linux 学习(二)

    Linux相关命令 命令 说明 startx 当前用户界面切换至图形界面 init5 切换至另一用户的图形化界面 init3 从图形界面切换回文本界面 pwd 显示当前用户路径 logout 注销 s ...

  10. 2星|《约见投资人》:A股上市公司软文集

    约见资本人:58家上市公司创始人亲述创业之路 全书写了58个A股上市公司的故事,基本是宣传上市公司老总的软文.基本的套路是创始人历尽苦难创立了公司,取得了好业绩.最希望看的分析与数据几乎没有.看了一小 ...