虽然已经AC,但这种思路为什么RE???求大佬指导
查看原帖
虽然已经AC,但这种思路为什么RE???求大佬指导
933604
LYBT楼主2023/8/10 19:27
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,x,num[N*4];
inline void make_tree(int x,int k){
	if(num[k]==0){
		num[k]=x;
		return ;
	}
	if(x<=num[k]) make_tree(x,k*2);
	if(x>num[k]) make_tree(x,k*2+1);
}
inline void add_tree(int k){
	if(num[k*2]) add_tree(k*2);
	cout<<num[k]<<" ";
	if(num[k*2+1]) add_tree(k*2+1);
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		make_tree(x,1);
	} 
	add_tree(1);
	return 0; 
}
2023/8/10 19:27
加载中...