fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long stack_[1000005];
  5. long long n_stack = 0;
  6.  
  7. void themVao(long long x)
  8. {
  9. n_stack++;
  10. stack_[n_stack] = x;
  11. }
  12.  
  13. long long layRa()
  14. {
  15. return stack_[n_stack];
  16. }
  17.  
  18. void xoa()
  19. {
  20. n_stack--;
  21. }
  22.  
  23. long long n, A[100005];
  24.  
  25. int main()
  26. {
  27. ios_base::sync_with_stdio(0);
  28. cin >> n;
  29. themVao(0);
  30. for (int i=1; i<=n; i++) cin >> A[i];
  31. for (int i=1; i<=n; i++)
  32. {
  33. while (layRa() > A[i]) xoa();
  34. cout << layRa() << " ";
  35. themVao(A[i]);
  36. }
  37.  
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
Success #stdin #stdout 0s 4708KB
stdin
Standard input is empty
stdout
Standard output is empty