QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#576309#9313. Make Max22333322WA 0ms3808kbC++14938b2024-09-19 19:52:402024-09-19 19:52:40

Judging History

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

  • [2024-09-19 19:52:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-09-19 19:52:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5,inf=1e9+1;
#define int long long 
int a[mxn],t,n;
struct A
{
    int pre,num,size;
};
signed main()
{   
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&n);
        for(int i=1;i<=n;i++) scanf("%lld",a+i);a[++n]=1e9+1;
        stack<A>s;
        s.push({inf,inf,0});
        int ans=0,p=1;
        while(p<=n)
        {
            A &x=s.top();
            if(a[p]<x.num) s.push({x.num,a[p],1}),p++;
            else if(a[p]==x.num) x.size++,p++;
            else if(x.pre>a[p])
            {
                ans+=x.size;
                x={x.pre,a[p],++x.size};
                p++;
            }
            else if(x.pre<=a[p])
            {
                ans+=x.size;
                s.pop();
                s.top().size+=x.size;
            }
        }
        printf("%lld",ans-n+1);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3808kb

input:

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

output:

1033

result:

wrong answer 1st numbers differ - expected: '1', found: '1033'