fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. stack<int> s;
  7. int sp = 0;
  8. int c = 0, cnt = 0;
  9. int n;
  10. cin>>n;
  11. while(n--)
  12. {
  13. int x; cin>>x;
  14. if(x==1)
  15. cin>>sp;
  16. while(!s.empty() && sp>s.top())
  17. {
  18. s.pop();
  19. c++;
  20. }
  21. if(x==6) cnt++;
  22. if(x==4) cnt = 0;
  23. if(x==2) {
  24. c+=cnt;
  25. cnt = 0;
  26. }
  27. if(x==5){
  28. while(!s.empty()) s.pop();
  29. }
  30. if(x==3)
  31. {
  32. int maxs; cin>>maxs;
  33. s.push(maxs);
  34. }
  35. }
  36. if(!s.empty() && s.top()<sp)
  37. c++;
  38. cout<<c<<endl;
  39. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
0