为啥超内存?指针被歧视了?
求大佬帮查错
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long myint;
inline myint read(){
myint x=0,f=1;char ch=getchar();
while (!isdigit(ch)&&~ch){if (ch=='-') f=-1;ch=getchar();}
if(ch==-1)return -1;
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void print(myint a){
if(a<0)putchar('-'),a=-a;
if(a>=10)print(a/10);
putchar(a%10+48);
}
struct trie{
trie*son[2]={};
}root;
void insert(int p){
trie*now=&root;
for(int i=1>=1){
bool sf=p&i;
if(now->son[sf]==NULL)
now->son[sf]=new trie();
now=now->son[sf];
}
}
int search(int p){
int ans=0;
trie*now=&root;
for(int i=1>=1){
bool sf=p&i;
if(now->son[!sf]!=NULL)
now=now->son[!sf],ans|=i;
else now=now->son[sf];
}
return ans;
}
int n=read();
signed main(){
int _max=0;
for(int i=1;i<=n;i++){
int a=read();
insert(a);
_max=max(_max,search(a));
}
print(_max);
return ~EOF;
}
深信服公司福利 832人发布