This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
const int nmax = 1e6 + 7;
struct insula {
int val, ind;
} v[nmax];
int root[nmax], sum[nmax];
bool f[nmax];
bool cmp(insula a, insula b) {
return a.val > b.val;
}
int find(int x) {
if(root[x] == x) {
return x;
}
root[x] = find(root[x]);
return root[x];
}
void unite(int a, int b) {
if(sum[a] < sum[b]) {
swap(a, b);
}
sum[a] += sum[b];
root[b] = a;
}
int32_t main() {
int n, maxx = 0, cnt = 0;
cin >> n;
for(int i = 1; i <= n; i ++) {
cin >> v[i].val;
v[i].ind = i;
}
sort(v + 1, v + n + 1, cmp);
for(int i = 1; i <= n; i ++) {
f[v[i].ind] = 1;
if(f[v[i].ind - 1] == 0 && f[v[i].ind + 1] == 0) {
cnt ++;
root[v[i].ind] = v[i].ind;
sum[v[i].ind] = 1;
} else if(f[v[i].ind - 1] == 1 && f[v[i].ind + 1] == 0) {
root[v[i].ind] = v[i].ind;
sum[v[i].ind] = 1;
unite(v[i].ind, find(v[i].ind - 1));
} else if(f[v[i].ind + 1] == 1 && f[v[i].ind - 1] == 0) {
root[v[i].ind] = v[i].ind;
sum[v[i].ind] = 1;
unite(v[i].ind, find(v[i].ind + 1));
} else {
cnt --;
root[v[i].ind] = v[i].ind;
sum[v[i].ind] = 1;
unite(v[i].ind, find(v[i].ind + 1));
unite(find(v[i].ind), find(v[i].ind - 1));
}
if(v[i].val != v[i + 1].val) {
maxx = max(maxx, cnt);
}
}
cout << maxx;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |