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;
typedef long long ll;
typedef double db;
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define repp(i,a,b) for(ll i = (a); i <= (b); i++)
#define repm(i, a, b) for (ll i = (a); i >= (b); i--)
#define repz(i, a, b) for (ll i = (a); i < (b); i++)
const long long MOD = 1e9+7, N = 1e6 + 5, M = 1e3+5, INF = 1e9;
ll tc = 1, n, m,k,ar[N];
string s, ye = "YES", no = "NO", nu;
vector<pairll> ed[2], blu;
void fastt(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void input(){
cin >> n;
ar[0] = 0;
repp(i,1,n) cin >> ar[i];
}
void solve(){
set<ll> stz;
ll ans = 1, pre, ri = 1e18;
repp(i,1,n){
bool chen = 0;
if(ar[i] < ar[i-1]){
chen = 1;
}
else{
if(ri < ar[i]) chen = 1;
}
stz.insert(ar[i]);
if(chen){
ans++;
auto it = stz.lower_bound(ar[i]);
it++;
if (it == stz.end()) ri = 1e18;
else ri = *it;
}
}
cout << ans << endl;
}
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
fastt();
while(tc--){
input();
solve();
}
}
/*
3
1 2 3
1 2 3
5
2 8 6 3 1
1 2 3 6 8
(n-1)/2
*/
Compilation message (stderr)
money.cpp: In function 'void solve()':
money.cpp:37:15: warning: unused variable 'pre' [-Wunused-variable]
37 | ll ans = 1, pre, ri = 1e18;
| ^~~
# | 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... |