#include<bits/stdc++.h> #define MAX 100000 int n; int numbers[MAX+1]; int position[MAX+1]; structfenwick { int a[MAX+1]; fenwick() { memset( a, 0, sizeof a ); } intquery( int X ){ int ret = 0; for( int x = X; x > 0; x -= x&-x ) ret += a[x]; return ret; } intsum( int lo, int hi ){ returnquery( hi ) - query( lo-1 ); } voidadd( int X, int val ){ for( int x = X; x <= n; x += x&-x ) a[x] += val; } } alive; intmain( void ){ scanf( "%d", &n ); for( int i = 1; i <= n; ++i ) { scanf( "%d", &numbers[i] ); position[numbers[i]] = i; alive.add( i, 1 ); } int mini = 1, maxi = n;