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;
int main(){
cin.tie(0) -> ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n);
for(int i=0;i<n;i++) cin >> a[i];
set<int> s;
int ans = 0, i = 0;
while(i < n)
{
s.insert(a[i]);
if(a[i + 1] < a[i]) break;
i++;
}
for(;i<n;i++)
{
auto x = s.upper_bound(a[i-1]);
ans++;
int y;
if(x == s.end())
{
y = a[i];
while(i < n)
{
s.insert(a[i]);
if(a[i + 1] < a[i]) break;
i++;
}
}
else if(a[i] <= *x)
{
y = *x;
while(i < n && a[i] <= y)
{
s.insert(a[i]);
if(a[i + 1] < a[i]) break;
i++;
}
}
else // a[i] > the el after prev element
{
s.insert(a[i]);
}
}
cout << ans << '\n';
}
# | 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... |