QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#579184 | #9313. Make Max | dxr | WA | 1ms | 5576kb | C++14 | 757b | 2024-09-21 10:20:27 | 2024-09-21 10:20:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3e5+5;
int a[N],l[N],r[N];
void solve()
{
// int a[N],l[N],r[N];
int n; cin>>n;
stack<int> s;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=n;i>=1;i--)
{
while(!s.empty()&&a[s.top()]<a[i]) s.pop();
r[i]=s.empty()? n+1:s.top();
s.push(i);
}
while(!s.empty()) s.pop();
for(int i=1;i<=n;i++)
{
while(!s.empty()&&a[s.top()]<a[i]) s.pop();
l[i]=s.empty()?0:s.top();
s.push(i);
}
ll ans=0;
for(int i=1;i<=n;i++)cout<<l[i]<<"\t"<<r[i]<<endl;;
for(int i=1;i<=n;i++) ans+=r[i]-l[i]-2;
cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t; cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5576kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
0 2 0 3 1 0 2 1 3 0 0 2 1 3 2 4 0 5 4 6 5 7 6 8 3 0 2 0 3 0 4 3
result:
wrong answer 1st numbers differ - expected: '1', found: '0'