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>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
multiset<int> s;
s.insert(1e9);
s.insert(a[0]);
int start = -1;
for (int i = 1; i < n; ++i) {
if (a[i - 1] > a[i]) {
start = i;
break;
}
s.insert(a[i]);
}
if (start == -1) {
cout << 1;
return;
}
int ans = 1;
for (int i = start; i < n; ++i) {
int it = *s.upper_bound(a[i]);
int j = i + 1;
while (j < n && a[j] <= it && a[j] >= a[j - 1]) {
s.insert(a[j]);
++j;
}
s.insert(a[i]);
i = j - 1;
++ans;
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
# | 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... |