QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#568482#9313. Make MaxjianwuTL 0ms0kbC++171.1kb2024-09-16 16:42:502024-09-16 16:42:50

Judging History

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

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

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pa;

ll t,n;


void solve()
{
    vector<ll> arr;
    arr.push_back(0);
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        ll u;
        cin>>u;
        arr.push_back(u);
    }
    stack<pa> s;
    ll ans=0;
    s.push({arr[1],1});
    for(ll i=2;i<=n;i++)
    {
        if(s.top().first>arr[i])
        {
            s.push({arr[i],i});
            continue;
        }
//        else
        {
            ll wz=-1;
            while(!s.empty() && s.top().first<arr[i])
            {
                ans+=i-=s.top().second;
                wz=s.top().second;
                s.pop();
            }
            if(s.empty() || s.top().first!=arr[i])
            {
                s.push({arr[i],wz});
            }
        }
    }
    while(s.size()>1)
    {
        ans+=n-s.top().second;
        s.pop();
    }
    cout<<ans<<'\n';
}

signed main()
{
//    ios::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);
    cin>>t;
    while(t-->0)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:


result: