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 <iostream>
#define MAX_N 1000000
#define MAX_A 1000000
using namespace std;
int v[MAX_N];
struct AIB {
int aib[MAX_A + 1];
void update( int i, int x ) {
while ( i <= MAX_A ) {
aib[i] += x;
i += (i & -i);
}
}
int query( int i ) {
int s;
s = 0;
while ( i > 0 ) {
s += aib[i];
i -= (i & -i);
}
return s;
}
};
AIB frecv;
int main() {
int n, subSegm, i, j;
cin >> n;
for ( i = 0; i < n; i++ )
cin >> v[i];
subSegm = 0;
i = 0;
while ( i < n ) {
j = i + 1;
while ( j < n && v[j - 1] <= v[j] && frecv.query( v[j] - 1 ) - frecv.query( v[i] ) <= 0 )
j++;
for ( ; i < j; i++ )
frecv.update( v[i], 1 );
subSegm++;
}
cout << subSegm;
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... |