/* written by Pankaj Kumar. country:-INDIA */ #include #include #include using namespace std; using namespace __gnu_pbds; typedef long long ll ; typedef vector vl; #define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0); // define values. // #define mod 1000000007 #define phi 1.618 /* Abbrevations */ #define ff first #define ss second #define mp make_pair #define line cout<>arr[i]; // Some print #define no cout<<"NO"<>test;while(test--) // sort #define all(V) (V).begin(),(V).end() #define srt(V) sort(all(V)) #define srtGreat(V) sort(all(V),greater()) #define printv(v) for(ll i=0;i0) { if(y%2==1) { res*=x; // res=res%mod; } y/=2; x*=x; // x=x%mod; } return res; } // datatype definination #define ordered_set tree,rb_tree_tag,tree_order_statistics_node_update> /* ascii value A=65,Z=90,a=97,z=122 */ /* -----------------------------------------------------------------------------------*/ ll solve() { ll n; cin>>n; vl v(n,0); for(ll i=0;i>v[i]; vl nsl,nsr; ll maxo=0; // for nsl stack> st; st.push({0,-1}); for(ll i=0;i0&&st.top().ff>=v[i]) st.pop(); if(st.size()==0) nsl.pb(-1); else nsl.pb(st.top().ss); } st.push({v[i],i}); } // for nsr stack> st1; st1.push({0,n}); for(ll i=n-1;i>=0;i--) { if(st1.empty()) nsr.pb(-1); else if(st1.top().ff0&&st1.top().ff>=v[i]) st1.pop(); if(st1.size()==0) nsr.pb(-1); else nsr.pb(st1.top().ss); } st1.push({v[i],i}); } reverse(all(nsr)); for(ll i=0;i