-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsubseq.cpp
More file actions
executable file
·59 lines (55 loc) · 815 Bytes
/
consubseq.cpp
File metadata and controls
executable file
·59 lines (55 loc) · 815 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define ft first
#define sd second
#define vi vector<int>
int main(void)
{
ll n;
cin>>n;
ll a[n+1];
for(ll id=1; id<n+1; id++)
cin>>a[id];
ll dp[n+1][2];
map<ll, ll> mp;
ll mlen=0, ind=1;
for(ll i=1; i<n+1; i++)
{
if(mp[a[i]-1])
{
dp[i][0]=mp[a[i]-1];
dp[i][1]=1+dp[(mp[a[i]-1])][1];
if(dp[i][1]>mlen)
{
mlen=dp[i][1];
ind=i;
}
}
else
{
dp[i][0]=0;
dp[i][1]=0;
}
if(!mp[a[i]])
mp[a[i]]=i;
else
{
if(dp[(mp[a[i]])][1]<dp[i][1])
mp[a[i]]=i;
}
}
cout<<mlen+1<<endl;
vi ans;
while(ind!=0)
{
ans.pb(ind);
ind=dp[ind][0];
}
for(ll i=ans.size()-1;i>=0;i--)
cout<<ans[i]<<" ";
return 0;
}