fork download
  1. #include<iostream>
  2. #include<stack>
  3. using namespace std;
  4. void printSpan(int arr[],int n){
  5. stack<int>s;
  6. int span;
  7. int ans[1000003]={};
  8. for(int day=1;day<=n;day++){
  9. int curPrice = arr[day];
  10. s.push(day);
  11. while(!s.empty()){
  12. if(arr[s.top()]<curPrice){
  13. span = 1;
  14. }
  15. else{
  16. span = s.top()+day;
  17. }
  18. }
  19. arr[day]=span;
  20. }
  21. for(int i=0;i<n;i++){
  22. cout<<ans[i]<<" ";
  23. }
  24. cout<<"END";
  25. }
  26.  
  27. int main(){
  28. int arr[1000003];
  29. int n;
  30. cin>>n;
  31. for(int i=0;i<n;i++){
  32. cin>>arr[i];
  33. }
  34. printSpan(arr,n);
  35. return 0;}
  36.  
Time limit exceeded #stdin #stdout 5s 7272KB
stdin
5
30 35 40 38 35
stdout
Standard output is empty