L2-1 堆宝塔 - B107 2023级选拔春季开学测重现 (pintia.cn)
#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int N=2e5+6;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
vector<int>ve1,ve2;
vector<vector<int> >ve;
void solve()
{int n,x;cin>>n;while(n--){cin>>x;if(ve1.empty()||ve1.back()>x)ve1.push_back(x);else if(ve2.empty()||ve2.back()<x)ve2.push_back(x);else{ve.push_back(ve1);ve1.clear();while(!ve2.empty()&&ve2.back()>x){ve1.push_back(ve2.back());ve2.pop_back();}ve1.push_back(x);}}if(!ve1.empty())ve.push_back(ve1);if(!ve2.empty())ve.push_back(ve2);//cout<<ve1.size()<<endl;int max1=-inf;for(auto &it:ve){max1=max(max1,(int)it.size());
//要在it.size()前加(int),因为vector它返回一个无符号整数类型的,所以要强制转换一下}cout<<ve.size()<<' '<<max1;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t=1;//cin>>t;while(t--){solve();}return 0;
}