#include <bits/stdc++.h>
#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))
constexpr bool dbg = 1;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl
#define int long long
#define ld long double
#define pb push_back
using namespace std;
#define rg ranges
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n;
cin >> n;
vector<int> v(n);
rep(i, 0, n) cin >> v[i];
int ans = 0;
stack<int> S;
rep(i, 0, 2 * n) {
auto x = v[(2 * n - i) % n];
while(S.size() && S.top() <= x) S.pop();
S.push(x);
ans = max(ans, (int)S.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 29 30 31 32 33 34 35 | #include <bits/stdc++.h> #define rep(a,b,c) for(auto a = (b); a != (c); a++) #define repD(a,b,c) for(auto a = (b); a != (c); a--) #define repIn(a, b) for(auto& a : (b)) #define repIn2(a, b, c) for(auto& [a, b] : (c)) constexpr bool dbg = 1; #define DEBUG if constexpr(dbg) #define DC DEBUG std::cerr #define eol std::endl #define int long long #define ld long double #define pb push_back using namespace std; #define rg ranges int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<int> v(n); rep(i, 0, n) cin >> v[i]; int ans = 0; stack<int> S; rep(i, 0, 2 * n) { auto x = v[(2 * n - i) % n]; while(S.size() && S.top() <= x) S.pop(); S.push(x); ans = max(ans, (int)S.size()); } cout << ans << '\n'; } |
English