QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#568609 | #9313. Make Max | jianwu | RE | 0ms | 0kb | C++17 | 1007b | 2024-09-16 17:22:22 | 2024-09-16 17:22:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t;
void solve()
{
ll n;
cin>>n;
ll arr[n+10];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
stack<pair<ll,ll>> st;
st.push({arr[0],0});
ll ans=0;
for(int i=1;i<n;i++)
{
if(st.top().first>arr[i])
{
st.push({arr[i],i});
}
else if(st.top().first<arr[i])
{
pair<ll,ll> op;
while(!st.empty() && st.top().first<arr[i])
{
op=st.top();
st.pop();
ans+=i-op.second;
}
if(!st.empty() && st.top().first!=arr[i])
{
st.push({arr[i],op.second});
}
}
}
while(st.size()>1)
{
ans+=n-st.top().second;
st.pop();
}
cout<<ans<<'\n';
}
signed main()
{
cin>>t;
while(t-->0)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0