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>
#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define ll long long
using namespace std;
const int N = 1e6 + 7;
const int mod = 1e9 + 7;
void solve()
{
int n;
int ans = 0;
set < int > s;
cin >> n;
vector < int > a(n + 1);
for( int i = 1; i <= n; i++ ){
cin >> a[i];
}
for( int i = 1 , j = 1; i <= n; i++ ){
if( a[i - 1] > a[i] ){
ans++;
for( ; j < i; j++ ){
s.insert(a[j]);
}
}
else{
auto it = s.upper_bound(a[j]);
if( it != s.end() && *it < a[i] ){
ans++;
for( ; j < i; j++ ){
s.insert(a[j]);
}
}
}
}
cout << ans + 1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int t = 1;//cin >> t;
while( t-- ){
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... |