/* 2026
* Maciej Szeptuch
*/
#include <algorithm>
#include <cstdio>
#include <deque>
const int MAX_LENGTH = 1048576;
int length;
int beauty[MAX_LENGTH];
std::deque<int> ord;
long unsigned result;
int main(void)
{
scanf("%d", &length);
for(int l = 0; l < length; ++l)
scanf("%d", &beauty[l]);
for(int l = 2 * length - 1; l >= 0; --l)
{
while(ord.size() && ord.front() - l > length)
ord.pop_front();
while(ord.size() && beauty[ord.back() % length] <= beauty[l % length])
ord.pop_back();
ord.push_back(l);
result = std::max(result, ord.size());
}
printf("%lu\n", result);
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 | /* 2026 * Maciej Szeptuch */ #include <algorithm> #include <cstdio> #include <deque> const int MAX_LENGTH = 1048576; int length; int beauty[MAX_LENGTH]; std::deque<int> ord; long unsigned result; int main(void) { scanf("%d", &length); for(int l = 0; l < length; ++l) scanf("%d", &beauty[l]); for(int l = 2 * length - 1; l >= 0; --l) { while(ord.size() && ord.front() - l > length) ord.pop_front(); while(ord.size() && beauty[ord.back() % length] <= beauty[l % length]) ord.pop_back(); ord.push_back(l); result = std::max(result, ord.size()); } printf("%lu\n", result); return 0; } |
English