# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38586 | MrPlany | Money (IZhO17_money) | C++14 | 613 ms | 9828 KiB |
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 <iostream>
using namespace std;
const int N = 1e6+5;
int n,a[N],t[N];
int sum(int k){
int s=0;
while(k>0){
s+=t[k];
k-=k&-k;
}
return s;
}
int add(int k, int val){
while(k<N){
t[k]+=val;
k+=k&-k;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int ans = 0;
for(int i=1;i<=n;i++){
int l,r;l = r = i;
while( a[r+1]>=a[r] && sum(a[r+1]-1) - sum(a[l])<=0) r++;
ans++;
while(l<=r) add(a[l++],1);
i=r;
}
cout << ans;
}
Compilation message (stderr)
# | 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... |