int main() { scanf("%d", &n); a[0] = INF; REP(i,1,n) { scanf("%d", a+i); int pre = 0; while (a[s[top]]<=a[i]) pre=s[top--]; L[i] = pre; R[s[top]] = i; s[++top] = i;; } }
处理完后根为s[0]