笛卡尔树板子

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]

posted @ 2019-04-09 22:20  uid001  阅读(122)  评论(0编辑  收藏  举报