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;
using ll = long long;
const int N = 1e6 + 66;
int a[N], ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
set<int>S = {N};
for (int i = 1 ; i <= n ; ++ i) cin >> a[i];
//{
//map<int,int> mp; for (int i = 1 ; i <= n ; ++ i) {
//assert(mp[a[i]]++ == 0);
//}
//}
for (int i = 1 ; i <= n ; ++ i) {
int j = i + 1;
while (j <= n && a[j] >= a[j - 1] && (a[j] == a[i] || S.lower_bound(a[j]) == S.upper_bound(a[i]))) ++j;
j--;
for (int l = i ; l <= j ; ++ l) {
S.insert(a[l]);
}
ans++;
//cout << i << " " << j << "\n";
i = j;
}
cout << ans;
}
# | 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... |