#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6+7;
int maxi[MAXN];
vector<int> input;
vector<int> tab;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, a;
cin >> n;
for(int i = 0; i < n; i++){
cin >> a;
input.push_back(a);
tab.push_back(a);
}
for(int x : input){
tab.push_back(x);
}
int wynik = 1;
deque<int> Q;
for(int i = tab.size()-1; i >= 0; i--){
while(!Q.empty() && tab[Q.back()] <= tab[i]){
Q.pop_back();
}
Q.push_back(i);
if(Q.front() - i >= n){
Q.pop_front();
}
maxi[i] = Q.size();
//cout << i << " " << maxi[i] << "\n";
wynik = max(wynik, maxi[i]);
}
cout << wynik << "\n";
return 0;
}
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 36 37 38 39 40 41 42 | #include <bits/stdc++.h> using namespace std; const int MAXN = 2e6+7; int maxi[MAXN]; vector<int> input; vector<int> tab; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, a; cin >> n; for(int i = 0; i < n; i++){ cin >> a; input.push_back(a); tab.push_back(a); } for(int x : input){ tab.push_back(x); } int wynik = 1; deque<int> Q; for(int i = tab.size()-1; i >= 0; i--){ while(!Q.empty() && tab[Q.back()] <= tab[i]){ Q.pop_back(); } Q.push_back(i); if(Q.front() - i >= n){ Q.pop_front(); } maxi[i] = Q.size(); //cout << i << " " << maxi[i] << "\n"; wynik = max(wynik, maxi[i]); } cout << wynik << "\n"; return 0; } |
English