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 <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n, a[ 1000001 ];
set <int> st;
main () {
cin >> n;
for ( int i = 1; i <= n; i ++ )
cin >> a[ i ];
ans = 1;
st.insert( a[ 1 ] );
for ( int i = 2; i <= n; i ++ ) {
if ( pos && a[ i ] != pos ) {
pos = 0;
ans ++;
st.insert( a[ i ] );
continue;
}
else if ( pos && a[ i ] == pos )
continue;
auto itt = st.upper_bound( a[ i ] );
if ( itt == st.begin() )
ans ++;
else {
itt = --itt;
if ( *itt != a[ i - 1 ] ) {
if ( *itt == a[ i ] && itt != st.begin() ) {
itt = --itt;
if ( *itt != a[ i - 1 ] )
ans ++;
else
pos = a[ i ];
}
else
ans ++;
}
}
st.insert( a[ i ] );
}
cout << ans;
}
/*
6
3 6 4 5 1 2
*/
Compilation message (stderr)
money.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main () {
| ^~~~
# | 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... |