#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]) cnt--, par[x] = y;
else if (!ck[x] && !ck[y]) cnt++, par[y] = x;
else par[y] = x;
ck[x] = ck[y] = 1;
};
map<int, vector<int>, greater<int>> add;
for (int i = 0; i < n; i++) add[a[i]].emplace_back(i);
for (auto &[x, y]: add) {
for (auto &e: y) {
if (e && a[e - 1] >= a[e]) mg(e - 1, e);
if (e != n - 1 && a[e + 1] >= a[e]) mg(e, e + 1);
if (!ck[e]) cnt++, ck[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);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
2040 KB |
Output is correct |
2 |
Correct |
13 ms |
1872 KB |
Output is correct |
3 |
Correct |
12 ms |
1700 KB |
Output is correct |
4 |
Correct |
13 ms |
1872 KB |
Output is correct |
5 |
Correct |
12 ms |
1912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
12112 KB |
Output is correct |
2 |
Correct |
30 ms |
12096 KB |
Output is correct |
3 |
Correct |
60 ms |
12104 KB |
Output is correct |
4 |
Correct |
62 ms |
12104 KB |
Output is correct |
5 |
Correct |
52 ms |
12108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
540 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
691 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |