//小根堆
for(int i=1;i<=n;i++){
int k=top;
while(k&&a[stk[k]]>a[i])k--;
if(k)rs[stk[k]]=i;
if(k<top)ls[i]=stk[k+1];
stk[++k]=i;top=k;
}