#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using lld= long double;
#define v vector
#define pb push_back
#define FF first
#define SS second
#define ALL(a) a.begin(), a.end()
#define R resize
#define debug(x) cerr<< #x << " " << x << "\n"
#define tak cout<<"YES\n"
#define nie cout<<"NO\n"
#define LINIJKI ios_base::sync_with_stdio(0);cin.tie(0)
int main()
{
LINIJKI;
ll ile;
cin>>ile;
v<ll>aa(ile*2);
for(ll i=0;i<ile;i++){
cin>>aa[i];
aa[i+ile] = aa[i];
}
deque<ll>kol;
ll ans = 0;
for(ll i=ile*2-1;i>=0;i--){
while(!kol.empty() && i+ile <= kol.back()) kol.pop_back();
while(!kol.empty() && aa[i] >= aa[kol.front()]) kol.pop_front();
kol.push_front(i);
ans = max(ans, (ll)kol.size());
}
cout<<ans;
}
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> using namespace std; using ll=long long; using lld= long double; #define v vector #define pb push_back #define FF first #define SS second #define ALL(a) a.begin(), a.end() #define R resize #define debug(x) cerr<< #x << " " << x << "\n" #define tak cout<<"YES\n" #define nie cout<<"NO\n" #define LINIJKI ios_base::sync_with_stdio(0);cin.tie(0) int main() { LINIJKI; ll ile; cin>>ile; v<ll>aa(ile*2); for(ll i=0;i<ile;i++){ cin>>aa[i]; aa[i+ile] = aa[i]; } deque<ll>kol; ll ans = 0; for(ll i=ile*2-1;i>=0;i--){ while(!kol.empty() && i+ile <= kol.back()) kol.pop_back(); while(!kol.empty() && aa[i] >= aa[kol.front()]) kol.pop_front(); kol.push_front(i); ans = max(ans, (ll)kol.size()); } cout<<ans; } |
English