# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168937 | beso123 | Money (IZhO17_money) | C++14 | 1198 ms | 62072 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 <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000006;
int n,a[N],fen[N],ans;
set <int> st;
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(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
scanf("%lld",&n);
for(int k=1;k<=n;k++){
scanf("%lld",&a[k]);
}
int l=1;
for(int r=1;r<=n+1;r++){
if(a[r-1]>a[r]){
ans++;
for(int j=l;j<=r-1;j++)
st.insert(a[j]);
l=r;
continue;
}
auto it=st.upper_bound(a[l]);
if(it!=st.end() && *it<a[r]){
ans++;
for(int j=l;j<=r-1;j++)
st.insert(a[j]);
l=r;
}
}
printf("%lld",ans);
return 0;
}
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... |