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,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 2e5 + 5, lg = 22, lng = 26, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
set<pp> st;
bool chk_is(int x){
auto it = st.lower_bound(pp(x, -1));
return it != end(st) && it->ff == x;
}
int pr(int x){
auto it = st.upper_bound(pp(x, -1));
return prev(it)->ff;
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n);
rep(i,0,n) cin >> a[i], st.insert({a[i], i});
int ans = 0, bl = 0; st.insert({-1, -1});
per(i,n-1,0){
if(i == n-1 || (bl > 1 && a[i] - a[i+1] && chk_is(a[i+1])) || (a[i] - a[i + 1] && pr(a[i+1]) - a[i])){
bl = 0, ans++;
}
if(i == n-1 || a[i] - a[i+1]) bl++;
st.erase(pp(a[i], i));
}
cout << ans << '\n';
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... |