#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
const int N = 1e6 + 5;
int par[N],sz[N],f[N];
pii a[N];
void make_set(int v) {
par[v] = v;
sz[v] = 1;
}
int find_set(int v) {
if (v == par[v]) return v;
int p = find_set(par[v]);
par[v] = p;
return p;
}
void union_sets(int a,int b) {
a = find_set(a),b = find_set(b);
if (a == b) return;
if (sz[a] < sz[b]) swap(a,b);
sz[a] += sz[b];
par[b] = a;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].fi;
a[i].se = i;
}
sort(a + 1,a + n + 1,greater<pii>());
for (int i = 1; i <= n; i++) make_set(i);
int ans = 0,cnt = 0,i = 1;
while (i <= n) {
int j = i;
while (j <= n && a[j].fi == a[i].fi) {
cnt++;
if (j > 1 && f[a[j].se - 1]) {
union_sets(a[j].se - 1,a[j].se);
cnt--;
}
if (j < n && f[a[j].se + 1]) {
union_sets(a[j].se + 1,a[j].se);
cnt--;
}
f[a[j].se] = 1;
j++;
}
i = j;
ans = max(ans,cnt);
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
2 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3664 KB |
Output is correct |
2 |
Correct |
15 ms |
3664 KB |
Output is correct |
3 |
Correct |
14 ms |
3664 KB |
Output is correct |
4 |
Correct |
15 ms |
3664 KB |
Output is correct |
5 |
Correct |
15 ms |
3664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
3664 KB |
Output is correct |
2 |
Correct |
10 ms |
3664 KB |
Output is correct |
3 |
Correct |
17 ms |
3664 KB |
Output is correct |
4 |
Correct |
16 ms |
3664 KB |
Output is correct |
5 |
Correct |
18 ms |
3664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
19992 KB |
Output is correct |
2 |
Correct |
182 ms |
19784 KB |
Output is correct |
3 |
Correct |
178 ms |
19984 KB |
Output is correct |
4 |
Correct |
175 ms |
19784 KB |
Output is correct |
5 |
Correct |
176 ms |
20008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
19788 KB |
Output is correct |
2 |
Correct |
208 ms |
19784 KB |
Output is correct |
3 |
Correct |
199 ms |
19784 KB |
Output is correct |
4 |
Correct |
167 ms |
19888 KB |
Output is correct |
5 |
Correct |
169 ms |
19880 KB |
Output is correct |