fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define MAXN 200'100
  4.  
  5. using namespace std;
  6.  
  7. int a[MAXN], b[MAXN];
  8.  
  9. int main()
  10. {
  11. cin.tie(NULL);
  12. ios_base::sync_with_stdio(false);
  13.  
  14. int n;
  15. cin >> n;
  16.  
  17. for (int i = 0; i<n; ++i)
  18. cin >> a[i], b[i] = a[i];
  19. sort(b,b+n,std::greater<int>());
  20. int cur_size = 0;
  21. set<int> s;
  22. for (int i = 0; i<n; ++i)
  23. {
  24. s.insert(a[i]);
  25. while (s.find(b[cur_size]) != s.end())
  26. cout << b[cur_size++] << ' ';
  27. cout << endl;
  28. }
  29. }
Success #stdin #stdout 0s 16808KB
stdin
3
3 1 2
stdout
3 

2 1