QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#568482 | #9313. Make Max | jianwu | TL | 0ms | 0kb | C++17 | 1.1kb | 2024-09-16 16:42:50 | 2024-09-16 16:42:50 |
Judging History
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