QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#568609#9313. Make MaxjianwuRE 0ms0kbC++171007b2024-09-16 17:22:222024-09-16 17:22:28

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 17:22:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-16 17:22:22]
  • 提交

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

result: