RT,按照大佬vectorwyx的意见添加了random_shuffle的部分,结果只捞到了60分,请问还有什么要改的吗qwq
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll MAXN=1e6+10;
ll lson[MAXN],rson[MAXN],v[MAXN];
ll ans=0,rt=0;
ll n,x;
void insert(ll node,ll num){
while(node){
if(v[node]<num){
if(not rson[node]){
ans+=1;
rson[node]=ans;
v[ans]=num;
break;
}
node=rson[node];
}
else{
if(not lson[node]){
ans+=1;
lson[node]=ans;
v[ans]=num;
break;
}
node=lson[node];
}
}
}
void zhong(ll node){
if(lson[node])zhong(lson[node]);
cout<<v[node]<<" ";
if(rson[node])zhong(rson[node]);
}
ll a[100001]={};
int main(){
ios::sync_with_stdio(false);
cin>>n;
ans=rt=1;
for(ll i=1;i<=n;i++)cin>>a[i];
random_shuffle(a+1,a+n+1);
v[ans]=a[1];
for(ll i=2;i<=n;i++)insert(rt,a[i]);
zhong(1);
return 0;
}