为什么MLE呢?
查看原帖
为什么MLE呢?
513717
Str_ywr楼主2023/8/29 21:33

问一下,在用splay求前驱的时候,如果传入一个指针就不会MLE ,否则就会

MLE的 https://www.luogu.com.cn/record/123256943

node* nextnode(int v){ 
	node *now=root;
	while(now->v <= v&&now->ch[1]!=null){
		now=now->ch[1];
	}
	if(now->ch[1]==null&&now->v <=v ){
		return null;
	}
	if(now->ch[0]==null) return now;
	node *ans=nextnode(v);
	if(ans==null) return now;
	else {
		splay(ans, null);
		return ans;
	}
}

不MLE的https://www.luogu.com.cn/record/123256785

node* nextnode(int v,node *nroot){//改变nroot不会改变root吧?  
	node *now=nroot;
	while(now->v <= v&&now->ch[1]!=null){
		now=now->ch[1];
	}
	if(now->ch[1]==null&&now->v <=v ){
		return null;
	}
	if(now->ch[0]==null) return now;
	node *ans=nextnode(v,now->ch[0]);
	if(ans==null) return now;
	else {
		splay(ans, null);
		return ans;
	}
}
2023/8/29 21:33
加载中...