博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ2309BST(树状数组)
阅读量:4701 次
发布时间:2019-06-09

本文共 1381 字,大约阅读时间需要 4 分钟。

BST
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9182   Accepted: 5613

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 <= 2
31 - 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

Source

 

强大的lowbit,树状数组太神奇了

1 #include
2 #include
3 #include
4 using namespace std; 5 int lowbit(int k) 6 { 7 return k & (-k); 8 } 9 int main()10 {11 int t,x;12 scanf("%d", &t);13 while(t--)14 {15 scanf("%d", &x);16 printf("%d %d\n",x - lowbit(x) + 1, x + lowbit(x) - 1);17 }18 return 0;19 }
View Code

 

转载于:https://www.cnblogs.com/zhaopAC/p/4984779.html

你可能感兴趣的文章
兴趣问题清单
查看>>
力扣——N叉树的后序遍历
查看>>
C++ namespace命名空间
查看>>
用Hadoop构建电影推荐系统
查看>>
automake连载---关于两个文件configure.in和Makefile.am的编写
查看>>
JQuery选择器中含有冒号的ID处理差异的分析
查看>>
分享:一款前端布局工具(alloydesigner)
查看>>
Application对象
查看>>
python爬虫实战(3)--图片下载器
查看>>
win7系统中开启wifi热点
查看>>
干货|最详尽的神经网络基础
查看>>
翻转字符串和左旋转字符串
查看>>
wampserver配置多站点
查看>>
找不到请求的 .Net Framework Data Provider。可能没有安装
查看>>
实验室管理系统(SQL+VS)
查看>>
C# protogen 处理protobuf生成cs文件
查看>>
oracle_SQL 实验查询及删除重复记录 依据条件 (row)
查看>>
SSM框架搭建
查看>>
[UE4]蓝图比C++慢10倍,是吗?
查看>>
使用IdleTest进行TDD单元测试驱动开发演练(1)
查看>>