#include <bits/stdc++.h>
#define y1 theboatman
#define make_struct(args...) {args}
using namespace std;
int main() {
cin.tie(0);
ios :: sync_with_stdio(0);
int n;
cin >> n;
vector <int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
int now = 0, x = 0;
while(now < n && x <= a[now]) {
x = a[now];
now++;
}
set <int> bank;
for(int i = 0; i < now; i++) {
bank.insert(a[i]);
}
int ans = 0;
for(int i = now; i < n; i++) {
//cout << a[i] << " " << *bank.begin() << " " << *--bank.end() << "\n";
if (a[i] >= *--bank.end()) {
int x = a[i];
while(i < n && x <= a[i]) {
x = a[i];
bank.insert(x);
i++;
}
i--;
}
else {
vector <int> lazy;
if (a[i] < *bank.begin()) {
int x = a[i];
while(i < n && x <= a[i] && a[i] <= *bank.begin()) {
x = a[i];
lazy.push_back(x);
i++;
}
i--;
}
else {
int x = a[i];
while(i < n && x <= a[i] && a[i] <= *--bank.end()) {
x = a[i];
lazy.push_back(x);
i++;
}
i--;
}
for(auto it : lazy) {
bank.insert(it);
}
}
ans++;
}
cout << ans + 1 << "\n";
return 0;
}
/*
3 5 1 2 2 2 2 2 2
3 5 1 2 4 4 4 4 4 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |