#include <iostream>
#include <vector>
#include <set>
using namespace std;
const int nmax = 2 * 1e5 + 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));
}
maxx = max(maxx, cnt);
}
cout << maxx;
return 0;
}
Compilation message
gw.cpp: In function 'int32_t main()':
gw.cpp:43:5: error: 'sort' was not declared in this scope; did you mean 'qsort'?
43 | sort(v + 1, v + n + 1, cmp);
| ^~~~
| qsort