fork download
  1. #include <iostream>
  2. const int maxn = 1000000;
  3. using namespace std;
  4. int n,a,d[maxn+2],dd[maxn+1],p,tplt,m;
  5. int main() {
  6. cin >> n;
  7. for (int i=1; i<=n; i++)
  8. {
  9. cin >> a;
  10. d[a] = i;
  11. }
  12. tplt = 0;
  13. p = n;
  14. m = n;
  15. for (int i=n; i>=1; i--)
  16. {
  17. if (d[i]==p)
  18. {
  19. tplt++;
  20. dd[m]=p-m+1;
  21. p = m-1;
  22. m = p;
  23. }
  24. else
  25. {
  26. if (d[i]<m) m = d[i];
  27. }
  28. }
  29. cout << tplt;
  30. for (int i=1; i<=n; i++)
  31. {
  32. if (dd[i]!=0)
  33. {
  34. cout << '\n' << dd[i] << ' ';
  35. }
  36. cout << i << ' ';
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 11272KB
stdin
6
2 1 5 4 3 6
stdout
3
2 1 2 
3 3 4 5 
1 6