POJ 2309 BST 树状数组基本操作

POJ 2309 BST 树状数组基本操作

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. 



<span>POJ 2309 BST 树状数组基本操作</span>

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

2
8
10

Sample Output

1 15
9 11

本题就考了树状数组的最最基本操作,对于会树状数组的人来说是太水了。

附个精简得不得了的代码,时间效率是O(1)

#include <stdio.h>
int main()
{
	int T, x;
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &x);
		printf("%d %d\n", x-(x&(-x))+1, x+(x&(-x))-1);
	}
	return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/119129.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • datagrip激活码2021(JetBrains全家桶)

    (datagrip激活码2021)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html0E14HXZ4QL-eyJsa…

    2022年3月28日
    211
  • java环境变量 的配置与详解(全网最详细教程)

    java环境变量 的配置与详解(全网最详细教程)笔者这学期开始学习java课程,学习java开发首先需要配置java运行环境变量。虽然上课老师也讲了如何配置java环境变量,可是笔者的同学还是有好多都不会配置,所以笔者最近配置了特别多次java环境变量。如下笔者详细解释从JDK安装到环境变量的装配。目录 JDK的下载与安装 配置java环境变量JAVA_HOME变量Path变量ClassPath变量classpath…

    2022年4月30日
    42
  • 开源报表工具 java_java生成报表

    开源报表工具 java_java生成报表BestOpenSourceReportingTools一文列出目前比较好的几种开源报表工具1.BIRTProjectBIRT是基于Eclipse的报表系统,很有竞争力。2.Pentaho侧重于从各种现有系统输出创建产生丰富复杂的报表内容。3.OpenRPTxTupleERPEditions的一部分,侧重ERP领域的报表4.OpenReports基于浏览器参数驱动动态报…

    2022年10月20日
    4
  • 文件服务器 ldap,windows下搭建ldap服务器[通俗易懂]

    文件服务器 ldap,windows下搭建ldap服务器[通俗易懂]windows下搭建ldap服务器内容精选换一换当您发现云服务器的运行速度变慢或云服务器突然出现网络断开的情况,则可能是云服务器的带宽和CPU利用率过高导致。如果您已经通过云监控服务创建过告警任务,当CPU或带宽利用率高时,系统会自动发送告警给您。Windows云服务器带宽流量过高或CPU利用率高,您可以按如下步骤进行排查:问题定位:定位影响云服务器带宽和CPU利用率高的进程。Wind本文以云服…

    2022年5月15日
    64
  • Java集合篇:HashSet

    Java集合篇:HashSet

    2021年10月4日
    30
  • PHP实现敏感词过滤系统「建议收藏」

    PHP实现敏感词过滤系统「建议收藏」码说明1、敏感词库维护更新脚本:reload_dict.php,提供自动更新字典库到trie-tree文件的过程PHP<?php//设置内存ini_set(‘memory_limit’,’128M’);//读取敏感词字典库$handle=fopen(‘dict.txt’,’r’);//生成空的trie-tree-filter$resTrie=trie_filter_new();while(!feof($handle)){$it

    2022年6月13日
    76

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号