BST
Time limit:1000 ms |
|
Memory limit:65536 K |
Total submissions:8440 |
|
Accepted:5093 |
Description
Consider an infinite full Binary Search Tree (see the figure below), the numbers in the nodes are 1, 2, 3 ,.... in a subtree whose root node is X, we can get the minimum number in this subtree by repeating going down the left node until the last level, and we can also find the maximum number by going down the right node. now you are given some queries as "What are the minimum and maximum numbers in The subtree whose root node is X? "Please try to find answers for there queries.
Input
In the input, the first line contains an integer N, which represents the number of queries. in the next n lines, each contains a number representing a subtree with root number x (1 <= x <= 231-1 ).
Output
There are n lines in total, the I-th of which contains the answer for the I-th query.
Sample Input
2810
Sample output
1 159 11
========================================================== ======================================
This is the use of the lowbit function. It is easy to understand the lowbit function.
# Include <stdio. h> # include <string. h> # include <stdlib. h> # include <algorithm> # include <math. h> # define Maxx 1000int lowbit (int x) {return X & (-x);} int main () {int I, j, n, m; scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% d", & M ); int CAS = lowbit (m); printf ("% d \ n", M-cas + 1, m + cas-1);} return 0 ;}