fork download
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define endl "\n"
  5. #define int long long
  6. #define faster() ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  7. #define maxArr 1000005
  8. void solve() {
  9. int n ; cin >> n ;
  10. int a[n + 1];
  11. map<int, int> dp ;
  12. int ans = 0 , last = 0 ;
  13. for(int i = 0 ; i < n ; i++){
  14. cin >> a[i] ;
  15. dp[a[i]] = max(dp[a[i]], dp[a[i] - 1] + 1 );
  16. // dp[a[i]] = dp[a[i] - 1] + 1 ;
  17. if(dp[a[i]] > ans){
  18. ans = dp[a[i]];
  19. last = a[i] ;
  20. }
  21. }
  22. vector<int> res ;
  23. for(int i = n - 1 ; i >= 0 ; i--){
  24. if(a[i] == last){
  25. res.push_back(i);
  26. --last ;
  27. }
  28. }
  29. reverse(res.begin(), res.end());
  30. cout << ans << endl;
  31. for(int idx : res) cout << idx + 1 << " ";
  32. }
  33.  
  34. signed main() {
  35. faster();
  36. int test = 1 ;
  37. // cin >> test ;
  38. while(test--) solve();
  39. return 0;
  40. }
  41.  
  42.  
Success #stdin #stdout 0.01s 5284KB
stdin
7
3 3 4 7 5 6 8
stdout
4
2 3 5 6