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;
#define f first
#define s second
#define pii pair <int, int>
#define pb push_back
const int N = 3e5 + 5;
int n, q, mn, r, mx;
int main() {
cin>>n;
int a[n+1];
set<int> s;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
int ans = 0;
for(int i = 1; i <= n; i++){
mn = a[i];
ans++;
for (int j = i; j <= n; j++){
if(a[j+1] < a[j]) { r = j; break; }
mx = a[j + 1];
auto it = s.lower_bound(mn);
if (it != s.end() && *it < mx) { r = j; break; }
}
for(int j = i; j <= r; j++){
s.insert(a[j]);
}
i = r;
}
cout << ans << endl;
}
# | 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... |