本题链接:PTA | 程序设计类实验辅助教学平台
题目:
样例:
|
4 5 |
思路:
这是一道模拟题,需要有耐心读题,跟着题目走一遍,就可以了。
代码详解如下:
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#define endl '\n'
#define int long long
#define YES puts("YES")
#define NO puts("NO")
#define umap unordered_map
#define All(x) x.begin(),x.end()
#pragma GCC optimize(3,"Ofast","inline")
#define IOS std::ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
const int N = 2e6 + 10;
inline void solve();signed main()
{
// freopen("a.txt", "r", stdin);IOS;int _t = 1;
// cin >> _t;while (_t--){solve();}return 0;
}
int n;
vector<int>a,b;
inline void solve()
{int sum = 0;int maxs = 0;cin >> n;int x;cin >> x;a.emplace_back(x); // 先拿第一个当底盘for(int i = 1;i < n;++i){cin >> x;if(x < a.back()) a.emplace_back(x);else{if(b.size()){if(x > b.back()) b.emplace_back(x);else{++sum;maxs = max(maxs,(int)a.size());a.clear();while(b.size() and b.back() > x){a.emplace_back(b.back());b.pop_back();}a.emplace_back(x);}}else b.emplace_back(x);}}maxs = max(maxs,(int)a.size());if(a.size()) ++sum;if(b.size()) ++sum;cout << sum << ' ' << maxs << endl;
}