hdu 4417 划分树

数学史学习资料:史前数学 著名物理学家伽莫夫(宇宙大爆炸理论以及核聚变理论的提出者)在他的科普书《从1到无穷大》中举了这样一个例子。两个原始部落的酋长比赛,看谁说的数字大。第一个酋长说了三,第二个酋长想了半天,然后说你赢了。你今天听起来觉得这两个人真可笑,至少说出四,岂不就赢了?但是对这两位酋长来讲,所拥有的东西就很少超过三个,比三个多的东西他们就觉得没有必要数清楚了,就用许多来形容了。也就是说,他们生活的环境限制了他们的认知。 阅读详情

Super Mario

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4041    Accepted Submission(s): 1862


Problem Description
Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory. Now the poor princess is in trouble again and Mario needs to save his lover. We regard the road to the boss’s castle as a line (the length is n), on every integer point i there is a brick on height hi. Now the question is how many bricks in [L, R] Mario can hit if the maximal height he can jump is H.
 

Input
The first line follows an integer T, the number of test data.
For each test data:
The first line contains two integers n, m (1 <= n <=10^5, 1 <= m <= 10^5), n is the length of the road, m is the number of queries.
Next line contains n integers, the height of each brick, the range is [0, 1000000000].
Next m lines, each line contains three integers L, R,H.( 0 <= L <= R < n 0 <= H <= 1000000000.)
 

Output
For each case, output "Case X: " (X is the case number starting from 1) followed by m lines, each line contains an integer. The ith integer is the number of bricks Mario can hit for the ith query.
 

Sample Input
1 10 10 0 5 2 7 5 4 3 8 7 7 2 8 6 3 5 0 1 3 1 1 9 4 0 1 0 3 5 5 5 5 1 4 6 3 1 5 7 5 7 3
 

Sample Output
Case 1: 4 0 0 3 1 2 0 1 5 1

题意:

查找指定区间内比x小的数的个数

思路:

稍微修改下划分树,但是不知道为什么一开始想的是二分- -,强行GG。写着很麻烦而且还是错的

划分数能很方便地求出了区间中小于等于第i个数的个数,在这个基础上稍作修改即可


/*
*/

#include <functional>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <Map>
using namespace std;
typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 100010;

int tree[20][maxn];
int sorted[maxn];
int toleft[20][maxn];

void build(int l,int r,int dep)  //模拟快排 并记录左树中比i小的个数
{
    if(l == r)
        return;
    int mid = (l+r)>>1;
    int same = mid-l+1;
    for(int i = l; i <= r; i++)
    {
        if(tree[dep][i] < sorted[mid])
            same--;
    }
    int lpos = l;
    int rpos = mid+1;
    for(int i = l; i <= r; i++)
    {
        if(tree[dep][i] < sorted[mid])
        {
            tree[dep+1][lpos++] = tree[dep][i];
        }
        else if(tree[dep][i] == sorted[mid] && same > 0)
        {
            tree[dep+1][lpos++] = tree[dep][i];
            same --;
        }
        else
        {
            tree[dep+1][rpos++] = tree[dep][i];
        }
        toleft[dep][i] = toleft[dep][l-1] + lpos -l;

    }
    build(l,mid,dep+1);
    build(mid+1,r,dep+1);
}


int query(int L,int R,int l,int r,int dep,int k)
{
    if(l == r)
    {
        if(tree[dep][l] <= k)
            return 1;
        return 0;
    }
    int mid = (L+R)>>1;
    int cnt = toleft[dep][r]-toleft[dep][l-1];
    if(sorted[mid] > k)          //如果比分界线小
    {
        int lpos = L+toleft[dep][l-1]-toleft[dep][L-1];
        int rpos = lpos+cnt-1;
        if(rpos >= lpos)
            return query(L,mid,lpos,rpos,dep+1,k);
        return 0;
    }
    else
    {
        int rpos = r+toleft[dep][R]-toleft[dep][r];
        int lpos = rpos-(r-l-cnt);
        return cnt+query(mid+1,R,lpos,rpos,dep+1,k);
    }
}


int main()
{
    int n,m,T;
    int cas = 1;
    scanf("%d",&T);
    while(T--)
    {

        scanf("%d%d",&n,&m);
        for(int i = 1; i <= n; i++)
        {
            scanf("%d",&sorted[i]);
            tree[0][i] = sorted[i];
        }
        sort(sorted+1,sorted+n+1);
        build(1,n,0);

        int l,r,to,ans;
        printf("Case %d:\n",cas++);
        while(m--)
        {
            scanf("%d%d%d",&l,&r,&to);
            l++;
            r++;
            ans = query(1,n,l,r,0,to);
            printf("%d\n",ans);
        }
    }
    return 0;
}




14、深入解析Sigma - Delta调制算法:从原理到应用 本博客深入解析了Sigma-Delta调制(SDM)算法的原理与应用,特别是在Super Audio CD(SA-CD)音频编码中的作用。文章探讨了传统SDM的局限性,并介绍了一系列改进型前瞻式SDM技术,如Trellis Sigma-Delta调制、高效网格Sigma-Delta调制和修剪树Sigma-Delta调制。这些技术通过降低计算复杂度和提升信号转换质量,在音频处理和无损数据压缩领域展现出巨大潜力。此外,博客还对不同SDM技术进行了性能比较,并分析了如何实现最大信噪比(SNR),为未来音频技术和数 阅读详情

相关推荐

FPGA以太网开发实战:YT8511 PHY芯片MDIO接口配置全流程(附Verilog代码)

本文详细介绍了FPGA以太网开发中YT8511 PHY芯片MDIO接口的配置全流程,包括MDIO接口技术解析、Verilog状态机设计、核心代码实现细节及实战调试经验。通过提供经过验证的Verilog代码和优化策略,帮助开发者快速掌握以太网PHY芯片配置技术,提升通信系统性能。

weixin_29184371的博客 232

【划分树+二分】HDU 4417 Super Mario

【划分树+二分】HDU 4417 Super Mario 第一次 耍划分树。。。 模板是找第k小的 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <s...

weixin_30640769的博客 107

从零搭建Python接口自动化测试框架:pytest+requests+Allure实战指南

接口自动化测试是现代软件工程中保障交付质量、提升测试效率的核心实践。其基本原理是通过脚本模拟客户端请求,对服务端接口进行自动化的功能验证、性能探测与回归测试,从而替代重复的手工操作。在技术实现上,Python凭借其简洁语法和丰富的生态,成为构建此类框架的主流选择,其中pytest测试框架、requests HTTP库和Allure报告工具构成了技术栈的黄金组合。这套技术方案的价值在于,它能将测试用例数据(如YAML文件)与执行逻辑分离,实现数据驱动测试,并通过持续集成(如Jenkins)无缝融入DevOps

weixin_31822733的博客 378

hdu4417-划分树

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 DescriptionMario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory. Now the poor princ...

测试 404

前端开发学习--登录和注册页面设计(html和css,可完成两个页面点击切换)

今天学习了登录和注册页面的设计,主要是HTML和CSS部分,注册和切换采用了Js代码进行,后面将通过js进行填写内容的验证,进而可通过JSP跳转到Servlet进行DAO数据的校验,这属于后端部分了。 总体设计思路:整个页面设计可以分为主体(content)、头部(content-header)、内容(content-body)三个部分组成,其中是主体是根部,包含了头部和内容,头部和内容各自下设两...

weixin_43691879的博客 1万+

QuestaSim使用Xilinx库的设置

安装QuestaSim

miracle_eicont的专栏 3409

hdu 4417 Super Mario (划分树)

http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意:求一组数列中任意区间内不大于h的数的个数。 思路:这题可以用划分树来做,我们只要找到区间内比h大的数中最小的那个,若它是该区间第k小的数,则答案即为k-1,我们可以通过二分来查找区间的第k小数,找到比h大的最小的数后即可得到答案,注意h可能比区间内的所有书都大,这个要特殊处理一下

ddyyxx的程序员之路 1495

XGBoost实战:从原理到调参,手把手教你提升模型性能(附Python代码)

本文深入解析XGBoost核心原理,并提供一套从数据准备、系统性调参到生产部署的完整实战指南。通过剖析目标函数、正则化项与分裂算法,帮助读者理解参数背后的数学逻辑,并利用交叉验证、早停法及自动化工具(如Optuna)高效提升模型性能。文中附有详尽的Python代码示例,涵盖类别特征处理、缺失值应对、不平衡数据调整及模型可视化等高级技巧。

weixin_29178069的博客 457

HDU 4417 Super Mario(划分树)

题目大意 给你 n(1<=n<=10^5) 个数,m(1<=m<=10^5) 个询问,每个询问的格式如下 L R H:从第 L 个数到第 R 个数中,小于等于 H 的数有多少个 做法分析 建立划分树 每次 query 的时候,二分答案即可,即二分这个区间中有多少个小于等于 H 的数 参考代码 HDU 4417 1 #...

weixin_30814319的博客 126

采用MPU6050的手势遥控器

随着社会的发展与进步,电子产品日益更新,个人家庭迎来了越来越多的智能家电。然而,现在的智能电子设备产品的遥控器多数都是按键形的。操作繁琐不直观,学习成本大。并且对于有老人小孩的家庭,给他们的操作带来了巨大的障碍。手势遥控器是指利用简单的手势来指挥电子设备,获得便捷的操作体验。让家庭成员都可以享受科技发展带来的福利。MPU6050是一个运动传感器,内置陀螺仪,再由电子设备利用判断结果做出相应的响应即...

Sakura的博客小站 6602

华为OD机考双机位C卷 - 最左侧冗余覆盖子串 (Java)

华为OD机考双机位C卷 - 最左侧冗余覆盖子串 (Java), 提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。

算法大师! 58

hdu4417 Super Mario

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417  二分查找+划分树 #include #include #include #include using namespace std; const int maxn=100010; int tree[30][maxn]; int sorted[maxn]; int tol

xaphoenix的博客 369

美特CRM mcc_login.jsp存在SQL注入漏洞

MetaCRM 是一种现代化的客户关系管理(CRM)平台,旨在通过集成和自动化的方式帮助企业管理与客户的关系,提高销售和服务效率。MetaCRM 的功能和特性通常涵盖了多个领域,包括销售、营销、客户服务、数据分析和自动化工具。

缘梦未来的博客 808

hdu4417(划分树)--二分

#include #include #include #include #include #include #include //hdu4417(划分树)--二分 #define N 100010 using namespace std; int sorted[N], p[20][N], num[20][N]; void build(int l, int r, int

u012432475的专栏 648

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

hdu 4417 划分树+二分

/*划分树+二分,二分第k个数 题意:给一列数..若干个询问..问(l,r,h)...在[l,r]范围内..有多少个数小于等于h*/ #include #include #include #define N 100100 using namespace std; int st[N],val[20][N],num[20][N]; void build(int x,int y,int cen) {

云华100的专栏 489

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

HDU 4417 Super Mario 划分树 + 二分

题目:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意:给定一个数组,下标从0开始,然后有一定数量的询问,问给定区间内小于等于给定值得个数 思路:二分枚举第k小值,小于等于给定值时就更新结果为k,二分完毕后输出结果即可 PS:话说当时正在宿舍看这道题,突闻系主任要点名,撒腿就跑,终于及时赶到。。。听所谓企业宣讲时想这道

弱智就要多努力 549

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

HDU 4417 划分树写法

Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory. Now the poor princess is in trouble again and Mario needs to save his lover. ...

weixin_30381317的博客 180

HDU 4417 划分树+二分

题意:有n个数,m个询问(l,r,k),问在区间[l,r] 有多少个数小于等于k。 划分树——查找区间第k大的数。。。。 利用划分树的性质,二分查找在区间[l,r]小于等于k的个数。 如果在区间第 i 大的数tmp>k,则往下找,如果tmp  #include #include #include #include #include #include #inc

不吸血的Vampire 716

hdu 4417(划分树)

将h值与划分树的中间值作比较,不小于中间值的话,答案加上查询区间进入左子树的个数并进入右子树,否则直接进入左子树。(注:查询区间可能为空) #include #include #include #include using namespace std; const int MAXN = 100010; int val[20][MAXN], toleft[20][MAXN]; int

Naruto_____的专栏 612

划分树 hdu4417Super Mario

划分树+二分枚举 http://acm.hdu.edu.cn/showproblem.php?pid=4417 划分树http://www.cnblogs.com/pony1993/archive/2012/07/17/2594544.html 直接搬来模板 打得 View Code 1 #include <iostream> 2 #include <...

weixin_30301183的博客 106

HDU 4417 Super Mario (二分+划分树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 #include&lt;bits/stdc++.h&gt; using namespace std; #define debug puts("YES"); #define rep(x,y,z) for(int (x)=(y);(x)&lt;(z);(x)++) #define ll lon...

满月照亮的路 167

hdu4417(单纯裸划分树)

来源:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意:给一些数,数中有重复的。还有一些询问,问的是[L,R] 区间内有多少个数小于h,有多次询问。 一般的方法肯定很容易超时,那这题就想到了划分树,接触过划分树的同学可能都知道用划分树查询区间内排列第k的数,这里只需把查询换为数值为k。用一个num表示小于等于k的数的个数,当k大

西天取经~ 520

hdu4417 ​ Super Mario 划分树

Super Mario Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 11899Accepted Submission(s): 4954 Problem Description Mario is world-famou...

skykone1的博客 179

HDU 4417 Super Mario 划分树

题意:给出长度为N的序列

leodestiny 496
上一篇: hdu 3473 划分树
下一篇: hdu 1806 RMQ
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值