#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int n;
int main() {
scanf("%d", &n);
vector<int> a(n), par(n); iota(par.begin(), par.end(), 0);
vector<bool> ck(n);
for (auto &e: a) scanf("%d", &e);
int cnt = 0, ans = 0;
function<int(int)> fset = [&] (int x) {return (par[x] == x ? x : par[x] = fset(par[x]));};
auto mg = [&] (int x, int y) {
if ((x = fset(x)) == (y = fset(y))) return;
if (ck[x] || ck[y]) par[y] = x, ck[x] = ck[y] = 1;
else {
cnt++;
par[y] = x; ck[x] = ck[y] = 1;
}
};
vector<int> c = a;
sort(c.begin(), c.end()); c.resize(unique(c.begin(), c.end()) - c.begin());
vector<vector<int>> add(n, vector<int>());
auto get = [&] (int x) {
return lower_bound(c.begin(), c.end(), x) - c.begin();
};
for (int i = 0; i < n; i++) add[get(a[i])].emplace_back(i);
for (int i = n - 1; i >= 0; i--) {
for (auto &e: add[i]) {
if (e && a[e - 1] >= a[e]) mg(e - 1, e);
if (e != n - 1 && a[e + 1] >= a[e]) mg(e, e + 1);
}
ans = max(ans, cnt);
}
printf("%d", ans);
}
Compilation message
gw.cpp: In function 'int main()':
gw.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
gw.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | for (auto &e: a) scanf("%d", &e);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
4692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
7756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
441 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
595 ms |
62388 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |