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 int long long
#define N 1000006
using namespace std;
int n,a[N],fen[N];
void UPD(int x,int val){
x+=1;
while(x<=N){
fen[x]+=val;
x=x+(x&(-x));
}
}
int GET(int x){
x+=1;
int sum=0;
while(x>=1){
sum+=fen[x];
x=x-(x&(-x));
}
return sum;
}
int get(int l,int r){
if(l>r)
return 0;
return GET(r)-GET(l-1);
}
main(){
cin>>n;
for(int k=1;k<=n;k++)
cin>>a[k];
int ans=1;
int j=0;
while(j<n && a[j]<a[j+1]){
UPD(a[j],1);
j++;
}
j++;
int prev=a[j];
for(int k=j;k<=n;k++){
int h=get(prev,a[k]);
if(a[k]>a[k+1] || h!=0){
ans++;
prev=a[k]+1;
}
else{
prev=a[k];
}
UPD(a[k],1);
}
cout<<ans;
return 0;
}
Compilation message (stderr)
money.cpp:27:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
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... |