-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsecsubseq.cpp
More file actions
40 lines (33 loc) · 781 Bytes
/
consecsubseq.cpp
File metadata and controls
40 lines (33 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
int n;
cin >> n;
int a[n];
for(int i = 0 ; i < n; i++) cin >> a[i];
unordered_map<int, int> mp;
mp[a[0]] = 1;
int mx = 1, mv = a[0];
for(int i = 1; i < n; i++){
if(mp.find(a[i]-1) != mp.end()) mp[a[i]] = mp[a[i]-1]+1;
else mp[a[i]] = 1;
if(mp[a[i]] > mx){
mx = mp[a[i]];
mv = a[i];
}
}
vector<int> fans;
for(int i = n; i>=0; i--){
if(a[i] == mv){
fans.push_back(i+1);
mv--;
}
}
reverse(fans.begin(), fans.end());
cout << fans.size() << endl;
for(const auto & a: fans) cout << a << " ";
return 0;
}