# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
168874 |
2019-12-16T19:18:52 Z |
beso123 |
Money (IZhO17_money) |
C++14 |
|
2 ms |
380 KB |
#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){
while(x<=N){
fen[x]+=val;
x=x+(x&(-x));
}
}
int GET(int x){
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;
UPD(a[1],1);
int j=1;
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);
//cout<<k<<' '<<prev+1<<' '<<a[k]-1<<' '<<h<<endl;
if(a[k]>a[k+1] || h!=0){
ans++;
if(k==n && h!=0)
ans++;
//cout<<k<<endl;
prev=a[k+1];
}
else{
prev=a[k];
}
UPD(a[k],1);
}
cout<<ans;
return 0;
}
Compilation message
money.cpp:25:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |