QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#568618 | #9313. Make Max | jianwu | WA | 0ms | 3556kb | C++17 | 1.0kb | 2024-09-16 17:24:14 | 2024-09-16 17:24:14 |
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.empty() && st.top().first>arr[i])
{
st.push({arr[i],i});
}
else if(!st.empty() && 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
Wrong Answer
time: 0ms
memory: 3556kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 1
result:
wrong answer 4th numbers differ - expected: '3', found: '1'