#include <cstdio>
#include <set>
#include <algorithm>
#include <numeric>
#define z exit(0)
#define mp make_pair
#define F first
#define S second
using namespace std;
using pii = pair<int,int>;
const int N = 1e6, inf = 1e9;
int m, idx[N];
set<pii> s;
int gw(int n, int H[]){
iota(idx, idx+n, 0);
auto cmp = [&](int i, int j) { return (H[i] == H[j]) ? i < j : H[i] < H[j]; };
sort(idx, idx+n, cmp);
int mx = -inf;
s.clear(); s.emplace(0, n-1);
for(int j = 0, k = 0; j<n; ){
for(k = j; k+1 < n && H[idx[k+1]] == H[idx[j]]; ++k){}
for(int i = j; i<=k; ++i){
auto itr = s.upper_bound(mp(idx[i], inf)); --itr;
if(itr == s.end()) continue;
int l = itr->F, r = itr->S;
s.erase(itr);
if(l <= idx[i]-1) s.emplace(l, idx[i]-1);
if(idx[i]+1 <= r) s.emplace(idx[i]+1, r);
}
j = k+1;
mx = max(mx, (int)s.size());
}
return mx;
}
signed main(){
int n; scanf("%d", &n);
int H[n];
for(int i = 0; i<n; ++i) scanf("%d", H+i);
printf("%d", gw(n, H));
}
Compilation message
gw.cpp: In function 'int main()':
gw.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
gw.cpp:39:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | for(int i = 0; i<n; ++i) scanf("%d", H+i);
| ~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
2388 KB |
Output is correct |
2 |
Correct |
31 ms |
2384 KB |
Output is correct |
3 |
Correct |
30 ms |
2396 KB |
Output is correct |
4 |
Correct |
31 ms |
2396 KB |
Output is correct |
5 |
Correct |
31 ms |
2592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
3164 KB |
Output is correct |
2 |
Correct |
26 ms |
4188 KB |
Output is correct |
3 |
Correct |
44 ms |
3072 KB |
Output is correct |
4 |
Correct |
46 ms |
3156 KB |
Output is correct |
5 |
Correct |
45 ms |
3064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
665 ms |
29008 KB |
Output is correct |
2 |
Correct |
651 ms |
29008 KB |
Output is correct |
3 |
Correct |
646 ms |
29012 KB |
Output is correct |
4 |
Correct |
649 ms |
29080 KB |
Output is correct |
5 |
Correct |
644 ms |
28432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
710 ms |
28496 KB |
Output is correct |
2 |
Correct |
719 ms |
28504 KB |
Output is correct |
3 |
Correct |
703 ms |
28496 KB |
Output is correct |
4 |
Correct |
393 ms |
22608 KB |
Output is correct |
5 |
Correct |
384 ms |
22752 KB |
Output is correct |