# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36857 | top34051 | Money (IZhO17_money) | C++14 | 286 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<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n;
int a[maxn], tree[maxn+5];
int sum(int x) {
int res = 0;
while(x>0) {
res += tree[x];
x -= x&-x;
}
return res;
}
void add(int x,int val) {
while(x<=maxn) {
tree[x] += val;
x += x&-x;
}
}
int main() {
int l,r,ans = 0;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++) {
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;
}
printf("%d",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... |