# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
763423 | KN200711 | Money (IZhO17_money) | C++14 | 1 ms | 340 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 MXN = 1e6;
int fen[1000001];
void add(int a, int c) {
while(a <= MXN) {
fen[a] += c;
a += a&(-a);
}
return;
}
int qry(int a) {
int res = 0;
while(a > 0) {
res += fen[a];
a -= a&(-a);
}
return res;
}
int main() {
int N;
scanf("%d", &N);
vector<int> arr(N);
for(int i=0;i<N;i++) scanf("%d", &arr[i]);
for(int i=1;i<=N;i++) {
add(i, 1);
}
int ans = 0;
for(int i=N-1;i>=0;i--) {
int nw = i;
int ls = qry(arr[i]);
i--;
while(i >= 0 && qry(arr[i]) == ls - 1) {
i--;
ls--;
}
ans++;
i++;
for(int c=i;c<=nw;c++) add(arr[c], -1);
}
printf("%d\n", 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... |