2 条题解

  • 0
    @ 2025-11-8 20:32:18

    按照题意模拟
    #include<bits/stdc++.h>
    using namespace std;
    int c[200100];
    int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    scanf("%d",&c[i]);
    }
    stack<int>a,b,d;
    a.push(c[1]);
    int ans=0,max1=-1;
    for(int i=2;i<=n;i++){
    if(c[i]<a.top()){
    a.push(c[i]);
    continue;
    }
    int z=b.size();
    if(z==0){
    b.push(c[i]);
    continue;
    }
    if(c[i]>b.top()){
    b.push(c[i]);
    continue;
    }
    int z1=a.size();
    max1=max(max1,z1);
    ans++;
    while(!a.empty()){
    a.pop();
    }
    while(!b.empty()){
    int z=b.top();
    if(z>c[i]){
    a.push(z);
    b.pop();
    }else{
    d.push(z);
    b.pop();
    }
    }
    a.push(c[i]);
    while(!d.empty()){
    int z=d.top();
    b.push(z);
    d.pop();
    }
    }
    int a2=a.size(),b2=b.size();
    if(a2>0){
    ans++;
    }
    if(b2>0){
    ans++;
    }
    max1=max(a2,max1);
    max1=max(b2,max1);
    printf("%d %d",ans,max1);
    return 0;
    }

    信息

    ID
    1186
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    67
    已通过
    15
    上传者