Treacode

122

(>__<)thank you

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const int N=1e5+5;
int n,a[N],trie[N*32][2],tot=1,ans;
bool end[N*31];
void insert(int t){
int p=1;
for(int i=30;i>=0;i--){
int x=(t>>i)&1;
if(trie[p][x]==0)trie[p][x]=++tot;
p=trie[p][x];
}
end[p]=1;
}
int search(int t){ 
int p=1,ans=0;
for(int i=30;i>=0;i--){
int x=(t>>i)&1;
if(trie[p][x^1]==0)p=trie[p][x];
else {
p=trie[p][x^1];//<=>p=trie[p][!x];
ans|=1<<i;
}
}
return ans;
}

int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
insert(a[i]);
ans=max(ans,search(a[i]));
}
printf("%d",ans);
}


Treacode
20天前
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const int N=2*1e5+5,M=1e4,T=(int)(log(N)/log(2))+5;
int n,m,a[N],f[N][T];
void prework(int n){
for(int i=1;i<=n;i++)f[i][0]=a[i];
int t=log(n)/log(2)+1;
for(int j=1;j<t;j++){
for(int i=1;i<=n-(1<<j)+1;i++){
f[i][j]=max(f[i][j-1],f[i+(1<<(j-1))][j-1]);
}
}
}
int ST_query(int l,int r){
int t=log(r-l+1)/log(2);
return max(f[l][t],f[r-(1<<t)+1][t]);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
prework(n);
scanf("%d",&m);
for(int i=1;i<=m;i++){
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",ST_query(a,b));
}
}
/*引入#include<cmath>

*/