Help me with this problem

Plz. tell me what i am doing wrong in this problem it is given wrong answer on single  test case.

#include<bits/stdc++.h>
using namespace std;  
#define ll long long
#define endl "\n" 
const int mod = 1e9+7;    
const int N = 1e6 + 2;      
  int dp[N];
  int a[N];
int main(){   
    ios_base::sync_with_stdio(false);     
       cin.tie(NULL);cout.tie(NULL);   
       int t  ;
       cin>>t;
       while(t--){
     ll n;
     cin>>n;
     for(int i = 0 ; i < n ;i++){
      cin>>a[i];
     }
     stack<ll>st;   
     dp[0] = 1;  
     st.push(a[0]);       
     for(int i = 1; i < n; i++){
      if(!st.empty() && st.top() <= a[i]){
        st.push(a[i]);
        dp[i] = dp[i - 1] + st.size();
      }
      else{    
        while(!st.empty()){
          st.pop();
        }
        st.push(a[i]);
        dp[i] = dp[i - 1] + st.size();   
      }
     }        
     cout<<dp[n - 1]<<endl;
   }   
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

sure

Can ypu please help me why my code is giving TLE?

Problem:Contest Page | CodeChef

LCA concept: LCA in a tree using Binary Lifting Technique - GeeksforGeeks
And rest concept of Editorialsit’s solutions

Code: Solution: 47337440 | CodeChef

Thanks