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 MAXN 1000010
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
using namespace std;
int a[MAXN], bit[MAXN], N, rez;
int query(int idx) {
int rez = 0;
for( ; idx ; idx -= idx&-idx) rez += bit[idx];
return rez;
}
void update(int idx, int val) {
for( ; idx < MAXN; idx += idx&-idx) bit[idx] += val;
}
int main() {
cin >> N >> a[1];
rez = 1;
for(int i = 2; i <= N; i++) {
cin >> a[i];
if(a[i] == a[i-1]) continue;
if(a[i-1] > a[i] || query(a[i]) > query(a[i-1])) {
rez++;
}
update(a[i-1], +1);
}
cout << rez;
return 0;
}
# | 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... |