# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37672 | Abelyan | Money (IZhO17_money) | C++14 | 256 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 MAX = 1000006;
int n, ans = 1, a[MAX], f[MAX];
void update(int i) {
while(i < MAX){
++f[i];
i += i & -i;
}
}
int query(int i) {
int ret = 0;
while(i > 0){
ret += f[i];
i -= i & -i;
}
return ret;
}
int main() {
scanf("%d",&n);
for(int i = 0; i < n; i++) scanf("%d", a+i);
for(int i = 1, last = 0; i < n; i++) {
if(a[i] < a[i-1] || query(a[i]-1) - query(a[last]) > 0) {
++ans;
while(last < i) update(a[last++]);
}
}
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... |