#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1e6 + 5;
list<int> l;
int a[N], n, ans;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i = 0; i < n; ++i) cin >> a[i];
l.push_back(0);
for(int i = 1; i < n; ++i) {
if(a[i] > a[l.back()]) l.push_back(i);
}
ans = l.size();
for(int i = n - 1; i > 0; --i) {
if(!l.empty() && l.back() == i) l.pop_back();
while(!l.empty() && a[i] >= a[l.front()]) l.pop_front();
l.push_front(i);
ans = max(ans, (int)l.size());
}
cout << ans << '\n';
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <bits/stdc++.h> using namespace std; constexpr int N = 1e6 + 5; list<int> l; int a[N], n, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 0; i < n; ++i) cin >> a[i]; l.push_back(0); for(int i = 1; i < n; ++i) { if(a[i] > a[l.back()]) l.push_back(i); } ans = l.size(); for(int i = n - 1; i > 0; --i) { if(!l.empty() && l.back() == i) l.pop_back(); while(!l.empty() && a[i] >= a[l.front()]) l.pop_front(); l.push_front(i); ans = max(ans, (int)l.size()); } cout << ans << '\n'; } |
English