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>
#define pb push_back
#define tree int h,int l,int r
#define left (h<<1),l,(l+r)>>1
#define right ((h<<1)|1),((l+r)>>1) + 1,r
#define f first
#define s second
#define ll long long
using namespace std;
const int N = 1e6 + 5;
int a[N],fen[N];
void upd(int idx){
while (idx <= 1000000){
fen[idx] += 1;
idx += (idx & (-idx));
}
}
int get(int idx){
int s = 0;
while (idx){
s += fen[idx];
idx -= (idx & (-idx));
}
return s;
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i = 1; i <= n; i++)
cin>>a[i];
int l = 1,ans=0;
while (l <= n){
int r = l,mn = a[l],mx = a[l];
while (r + 1 <= n){
if (a[r + 1] < a[r]) break;
int mn1 = min(mn,a[r + 1]),mx1 = max(mx,a[r + 1]);
if (get(mx1) - get(mn1 - 1) > 0) break;
r++;
}
for (int i = l; i <= r; i++) upd(a[i]);
l = r + 1;
++ans;
}
cout<<ans;
}
# | 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... |