# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
229341 | DodgeBallMan | Money (IZhO17_money) | C++14 | 5 ms | 384 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 N = 1e6 + 10;
int n, a[N], s[N], cnt, ans;
set<int> se;
void process( int idx ) {
//printf("%d\n",idx);
int l = s[idx], r = s[idx+1] - 1;
//printf("L : %d R : %d\n",l,r);
while( l < r ) {
int mid = l + r + 1 >> 1;
//printf("MID : %d %d\n",mid,s[mid]);
if( se.upper_bound( a[s[idx]] ) == se.lower_bound( a[mid] ) ) l = mid;
else r = mid - 1;
}
for( int i = s[idx] ; i <= l ; i++ ) se.insert( a[i] );
s[idx] = l + 1;
//printf("L : %d\n",l);
ans++;
return ;
}
int main()
{
scanf("%d",&n);
for( int i = 1 ; i <= n ; i++ ) scanf("%d",&a[i]);
a[0] = 2e9;
for( int i = 1 ; i <= n ; i++ ) if( a[i] < a[i-1] ) s[++cnt] = i;
s[++cnt] = n+1;
/*for( int i = 1 ; i <= cnt ; i++ ) printf("%d ", s[i]);
printf("\n");*/
for( int i = 1 ; i < cnt ; i++ ) {
do{
process( i );
}while( s[i] < s[i+1] );
}
printf("%d",ans);
return 0;
}
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... |