QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573018#9313. Make MaxHarold0895WA 28ms5064kbC++141.4kb2024-09-18 17:05:032024-09-18 17:05:05

Judging History

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

  • [2024-09-18 17:05:05]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:5064kb
  • [2024-09-18 17:05:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mxn=2e5+5,inf=0x3f3f3f3f;
#define int long long
int a[mxn],n;
struct ST{
    int pre;//当前元素的前一个元素
    int l,r;//当前元素的左右边界
    int num;//当前元素的值
};
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    stack<ST>s;
    s.push({inf,0,0,inf});//压入一个无穷大入栈
    int p=1;
    int ans=0;
    while(p<=n){//从左到右走一遍O(n)
        ST & temp=s.top();//栈顶
        if(a[p]<temp.num){//当前元素比栈顶小,还不能直接比较,需等后续元素入栈
            s.push({temp.num,p,p,a[p]});
            p++;
        }
        else if(a[p]==temp.num){//当前元素和栈顶相等,直接改栈顶的区间
            temp.r=p;
            p++;
        }
        //以下情况为(a[p]>temp.num)
        else if(temp.pre>a[p]){//三个元素从左到右为ABC,即B<C<A,栈顶元素和a[p]合并
            ans+=temp.r-temp.l+1;
            temp={temp.pre,temp.l,p,a[p]};//修改栈顶
            p++;
        }
        else if(temp.pre<=a[p]){//三个元素从左到右为ABC,即B<A<C,直到temp.pre>temp.num
            ans+=temp.r-temp.l+1;
            s.pop();
            s.top().r=p;
        }
    }
    cout<<ans<<'\n';
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T;
    cin>>T;
    while(T--)solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

input:

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

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Wrong Answer
time: 28ms
memory: 5064kb

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:

3977159
3785622

result:

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