#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+1,a[k]-1);
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
money.cpp:27:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |