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;
int n,a[1000007],bit[1000007];
int ans=1,cur=1;
void upd(int pos){
for(int i=pos;i<=1000000;i+=i&-i){
bit[i]++;
}
}
long long get(int pos){
long long res=0;
for(int i=pos;i>=1;i-=i&-i){
res+=bit[i];
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=2;i<=n;i++){
int res=get(a[i]-1);
res-=get(a[cur]);
if(a[i]<a[i-1] || res>0){
ans++;
while(cur<i){
upd(a[cur]);
cur++;
}
}
}
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... |