Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- typedef long long llint;
- int N; llint a[ 100005 ];
- struct node { node *c[ 2 ]; };
- node *root;
- void update( node *n, int p, llint x ) {
- if( p < 0 ) return;
- if( !n->c[(x>>p)&1] ) n->c[(x>>p)&1] = new node();
- update( n->c[(x>>p)&1], p-1, x );
- }
- llint query( node *n, int p, llint x ) {
- if( p < 0 ) return 0;
- if( n->c[!((x>>p)&1)] ) return query( n->c[!((x>>p)&1)], p-1, x )^(1LL<<p);
- return query( n->c[(x>>p)&1], p-1, x );
- }
- int main( void )
- {
- root = new node();
- scanf( "%d", &N );
- for( int i = 0; i < N; ++i ) {
- scanf( "%lld", a+i );
- update( root, 60, a[i] );
- }
- for( int i = 0; i < N; ++i )
- printf( "%lld\n", query( root, 60, a[i] ) );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement