QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#595644 | #9313. Make Max | Wwjq | WA | 1ms | 5636kb | C++14 | 906b | 2024-09-28 14:10:34 | 2024-09-28 14:10:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
long long a[200010];
int r[200010],l[200010];
int main ()
{
int t,i;
cin>>t;
long long n,ans=0;
stack<long long>q;
while(t--)
{
cin>>n;
ans=0;
stack<long long>q;
for(i=1;i<=n;i++)
cin>>a[i];
//you
for(i=1;i<=n;i++)
{
while(q.size()&&a[q.top()]<=a[i])
{
r[q.top()]=i;
q.pop();
}
q.push(i);
}
// for(i=1;i<=n;i++)
// cout<<r[i]<<" ";
// cout<<'\n';
while(q.size())
{
r[q.top()]=n+1;
q.pop();
}
for(i=n;i>=1;i--)
{
while(q.size()&&a[q.top()]<=a[i])
{
l[q.top()]=i;
q.pop();
}
q.push(i);
}
// for(i=1;i<=n;i++)
// cout<<l[i]<<" ";
// cout<<'\n';
while(q.size())
{
r[q.top()]=0;
q.pop();
}
for(i=1;i<=n;i++)
{
ans+=r[i]-i-1;
if (a[l[i]]!=a[i])
ans+=i-l[i]-1;
}
cout<<ans<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5636kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
-4 -2 -4 -9
result:
wrong answer 1st numbers differ - expected: '1', found: '-4'