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 <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
ll n,m,i,j,k,p,a[1000005],ans,u,v,t,q;
set<ll> s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
ans=1;
for(i=1;i<=n;i++)
{
if(a[i]>=a[i-1])
s.insert(a[i]);
else
break;
}
for(;i<=n;i++)
{
ans++;
set<ll>::iterator it=s.upper_bound(a[i]);
if(it==s.end())
{
s.insert(a[i]);
i++;
while(i<=n && a[i]>=a[i-1])
{
s.insert(a[i]);
i++;
}
i--;
}
else
{
u=*it;
s.insert(a[i]);
i++;
while(i<=n && a[i]>=a[i-1] && a[i]<=u)
{
s.insert(a[i]);
i++;
}
i--;
}
}
cout<<ans<<endl;
return 0;
}
# | 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... |