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 <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++) {
if (a[i] >= *--bank.end()) {
int x = a[i];
while(i < n && x <= a[i]) {
x = a[i];
bank.insert(x);
i++;
}
i--;
}
else {
if (a[i] < *bank.begin()) {
int x = a[i];
while(i < n && x <= a[i] && a[i] <= *bank.begin()) {
x = a[i];
bank.insert(x);
i++;
}
i--;
}
else {
int x = a[i];
while(i < n && x <= a[i] && a[i] <= *--bank.end()) {
x = a[i];
bank.insert(x);
i++;
}
i--;
}
}
ans++;
}
cout << ans << "\n";
return 0;
}
/*
1 5 6
*/
# | 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... |