POJ 3264 Balanced Lineup (线段树)

智能驾驶感知模块的测试评估方法(上) 对于智能驾驶系统而言,感知模块是开发难度最大、投入资源最多的核心部分。在智能驾驶开发团队内部,感知模块需要独立进行评测才能及早发现潜在缺陷或判断性能是否有改进。随着近几年BEV、OCC、E2E等新技术方案被越来越多企业应用,感知的评测变得越来越艰难,效率也变得越来越低下。本文作者基于在智驾测试行业多年经验,试图总结感知评测的基本规律和效率提升方法,以供读者一些启发。 阅读详情

Balanced Lineup
Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Submit

Status

Practice

POJ 3264
Description
For the daily milking, Farmer John’s N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous range of cows from the milking lineup to play the game. However, for all the cows to have fun they should not differ too much in height.

Farmer John has made a list of Q (1 ≤ Q ≤ 200,000) potential groups of cows and their heights (1 ≤ height ≤ 1,000,000). For each group, he wants your help to determine the difference in height between the shortest and the tallest cow in the group.

Input
Line 1: Two space-separated integers, N and Q.
Lines 2.. N+1: Line i+1 contains a single integer that is the height of cow i
Lines N+2.. N+ Q+1: Two integers A and B (1 ≤ A ≤ B ≤ N), representing the range of cows from A to B inclusive.
Output
Lines 1.. Q: Each line contains a single integer that is a response to a reply and indicates the difference in height between the tallest and shortest cow in the range.
Sample Input
6 3
1
7
3
4
2
5
1 5
4 6
2 2
Sample Output
6
3
0

线段树水题。节点里维护一个区间最大值和最小值。最后统计一下做个差就好了。

#include "iostream"
#include "string.h"
#include "cstdio"
#include "algorithm"
using namespace std;
int num[50005];
struct node
{
    int maxx,minn;
    int left,right;

}tree[50005*4];

int mymax,mymin;

void build(int root,int lf,int rt)
{
    tree[root].maxx=0;
    tree[root].minn=1000005;
    tree[root].left=lf;
    tree[root].right=rt;
    if(lf==rt)
    {
        tree[root].maxx=tree[root].minn=num[lf];
        return;
    }
    int mid=(lf+rt)/2;
    build(root*2,lf,mid);
    build(root*2+1,mid+1,rt);

    tree[root].minn=min(tree[root].minn,tree[root*2].minn);
    tree[root].minn=min(tree[root].minn,tree[root*2+1].minn);

    tree[root].maxx=max(tree[root].maxx,tree[root*2].maxx);
    tree[root].maxx=max(tree[root].maxx,tree[root*2+1].maxx);
    return;
}
void find(int root,int lf,int rt)
{
    if(mymin<=tree[root].minn&&mymax>=tree[root].maxx)
        return;
    if(lf<=tree[root].left&&rt>=tree[root].right)
    {
        mymax=max(mymax,tree[root].maxx);
        mymin=min(mymin,tree[root].minn);
        return;
    }
    if(tree[root].left==tree[root].right)
        return;
    int mid=(tree[root].left+tree[root].right)/2;
    if(rt<=mid)
        find(root*2,lf,rt);
    else if(lf>mid)
        find(root*2+1,lf,rt);
    else
    {
        find(root*2,lf,mid);
        find(root*2+1,mid+1,rt);
    }

    return;
}

int main()
{
    int n,q;
    while(~scanf("%d%d",&n,&q))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&num[i]);
        }
        build(1,1,n);
        int a,b;
        for(int i=1;i<=q;i++)
        {
            mymax=0;
            mymin=1000005;
            scanf("%d%d",&a,&b);
            find(1,a,b);
            printf("%d\n",mymax-mymin);
        }
    }
}

使用RustDesk或者AnyDesk的TCP隧道实现Codesys系列PLC的远程调试和下载 Codesys远程调试 阅读详情

相关推荐

手把手教你设计T型和Π型衰减器:从理论计算到实际搭建(含误差分析)

本文详细介绍了T型和Π型衰减器的设计方法,从理论计算到实际搭建,包括电阻值推导、元件选择技巧及误差分析。通过实例演示如何设计50Ω系统中的10dB衰减器,并提供了高频应用和优化策略,帮助电子工程师掌握阻抗匹配与信号衰减的核心技术。

weixin_33737774的博客 409

poj3264Balanced Lineup(线段树)

poj3264Balanced Lineup Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 48911   Accepted: 22908 Case Time Limit: 2000MS Description

luckcircle的博客 349

B0505S选型

    使用B0505S-1W已经有一段时间了,一直以来使用的是下面的电路,该电路摘自《CAN总线嵌入式开发——从入门到实战》一书。 参考金升阳的用户手册,手册上写道: 为了确保该模块能够高效可靠的工作,使用时,其输出最小负载不能小于额定负载的10%。若您所需功率确实较小,请在输出端并联一个电阻(电阻消耗功率与实际使用功率之和大于等于10%的额定功率)        由于使用该电源模...

动感小麦兜的博客 1万+

【线段树 + 详细注释】北大 poj 3264 Balanced Lineup

/* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2011 pan

panyanyany(飞雨幻沙) 1315

Geant4 案例分析(一): B1

本文是对Geant4 B1的案例分析,其中特定的功能不做介绍,而注重于各个文件的主要功能,以及它们组织的方式。

m0_51809467的博客 1585

如何用Bertalign快速搞定多语言句对齐?5分钟上手教程(附避坑指南)

本文详细介绍了如何利用Bertalign工具快速实现多语言句对齐,从安装配置到实战应用的全流程指南。通过LaBSE句向量技术,Bertalign显著提升了对齐准确率,支持25种语言的任意组合,特别适合处理复杂句式。文章还提供了常见问题的解决方案和性能优化技巧,帮助用户高效完成多语言文本对齐任务。

weixin_42538752的博客 358

Balanced Lineup poj3264 线段树

Balanced Lineup poj3264 线段树 题意 一串数,求出某个区间的最大值和最小值之间的差 解题思路 使用线段树,来维护最大值和最小值,使用两个查询函数,一个查区间最大值,一个查区间最小值,然后做差就好了,基本上就是线段树模板题 代码实现 #include<cstdio> #include<cstring> #include<algorit...

weixin_30367169的博客 152

从内外参推导IPM变换方程及代码实现(生成AVM环视拼接图)

最近想实现AVM拼接,看了不少博客和论文,不过比较愚钝,一直没能很好理解原理,尤其是怎么在实现时把下文中Z1和Z2消除的,所以严谨的推导了一下对应的公式,如有不对,水平有限,烦请指出~IPM变换(逆透视变换),顾名思义,即将正常透视效应消除的变换,变换结果为鸟瞰图BEV(俯视图);AVM环视拼接一般是将车身前后左右的四个鱼眼相机拼接成环视图(也是俯视),其使用的单应矩阵将四个相机转到同一个俯视坐标系。

mxdsdo09的博客 4182

POJ3264 Balanced Lineup(线段树)

POJ3264http://poj.org/problem?id=3264 线段树模版。 题目大意: Q次区间查询。 AC代码: #include <iostream> #include <cstdio> #include <cmath> using namespace std; const int maxn = 50000 + 5; int a[...

Sensente的博客 292

Numpy快速入门(np)!看这一篇就够了

Numpy快速入门(np)!看这一篇就够了

weixin_74009895的博客 2689

YOLOv11改进策略【模型轻量化】| 替换骨干网络为 2024轻量化网络MoblieNetV4:移动生态系统的通用模型

一、本文介绍 本文记录的是基于MobileNet V4的YOLOv11目标检测轻量化改进方法研究。MobileNet V4通过整合UIB、Mobile MQA以及优化的NAS策略,能够在在不降低性能指标的前提下,降低计算成本。本文配置了原论文中MNv4-Conv-S、MNv4-Conv-M、MNv4-Conv-L、MNv4-Hybrid-M和MNv4-Hybrid-L五种模型,以满足不同的需求。 模型 参数量 计算量 推理速度 YOLOv11m 20.0M 67.6GFLOPs 3.5ms

Limiiiing的博客 4475

[线段树] POJ 3264 balanced lineup

Balanced LineupTime Limit: 5000MS Memory Limit: 65536K Total Submissions: 33267 Accepted: 15615 Case Time Limit: 2000MS Description For the daily milking, Farmer John’s N cows (1 ≤ N ≤ 50,000) al

童凌的技术博客 596

YOLOv13改进目录一览 | 涉及卷积层、轻量化、注意力、损失函数、Backbone、SPPF、Neck、检测头等全方位改进

1️⃣ 已更新种不同的改进方案,专栏内的每篇文章皆,均可顺利运行。2️⃣ 订阅专栏即可进群获取以及从的各种答疑内容。3️⃣ 全新的YOLOv13改进专栏,,只为更好的满足论文发表的要求。专栏内容,专栏实时评分,全网最高,质量保证。🎫。。

Limiiiing的博客 9236

poj3264 Balanced Lineup 线段树

题目链接在这里 题目描述: 给出n个数q次询问,每次询问求[ x, y ]区间最大的数减去最小的数的结果。 思路分析: 用线段树的每个节点存储子节点的最大数和最小数,叶子节点的最大数和最小数是自己。 代码如下: #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;algorithm&gt; #include &l...

Joel 275

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

POJ3264Balanced Lineup(经典线段树)

Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 39618   Accepted: 18600 Case Time Limit: 2000MS Description For the daily milking, Farme

ACMan 456

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

poj 3264 Balanced Lineup(线段树、RMQ)

题目链接:http://poj.org/problem?id=3264 思路分析: 典型的区间统计问题,要求求出某段区间中的极值,可以使用线段树求解。 在线段树结点中存储区间中的最小值与最大值;查询时使用线段树的查询 方法并稍加修改即可进行查询区间中最大与最小值的功能。 代码(线段树解法): #include <limits> #include &l...

aqjh9999的博客 147

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

poj 3264 Balanced Lineup - 线段树

Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the c...

adx33526的博客 233

POJ 3264 Balanced Lineup 【线段树】

Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 50004 Accepted: 23434 Case Time Limit: 2000MS DescriptionFor the daily milking, Farmer John’s N cows (1 ≤ N ≤

博客已搬迁到http://www.cnblogs.com/cniwoq/ 352

POJ 3264 Balanced Lineup 线段树 / 平方分割

给出一个长度为 n(n

qq_53038151的博客 297

poj 3264 Balanced Lineup(线段树无区)

题目链接:    http://poj.org/problem?id=3264 题目大意:   给出初始化的区间值,m次查询                   每次查询区间[a,b]的最大值-最小值 解题思路:   线段树    更新: 无更新    查询:区间查询                   建立线段树的时候,每个结点存储左右子树的最大值和最小值

ンZee的解题报告 2452

poj 3264 Balanced Lineup (线段树模板题)

Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 40175   Accepted: 18865 Case Time Limit: 2000MS Description For the daily milking, Farme

01的世界 625

POJ_3264 Balanced Lineup 【线段树 + 区间查询】

一、题面 POJ3264 二、分析 典型的线段树的题,没有更新只有查询。 查询的时候需要注意的是,在判断区间是完全属于右子树还是左子树时,要根据建树的情况来选择,不然会出错。具体看代码 三、AC代码 1 #include <cstdio> 2 #include <cstdio> 3 #include <iostream> 4 #in...

weixin_30795127的博客 119

poj 3264 Balanced Lineup RMQ线段树实现

For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous range of cows from the

Lionel 1042

POJ3264-Balanced Lineup 【线段树】

For the daily milking, Farmer John'sNcows (1 ≤N≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things ...

独钓门前月 368

poj 3264 Balanced Lineup 线段树

这道题是线段树的入门提,但是这道题对递归的理解要求比较高。 代码如下: #include #include #include #include using namespace std; struct node { int lc,rc,mi,ma; }s[50010000]; int a[50010],mi=10000000,ma=-10; void build(int left,int r

小冷在努力~ 343

poj3264 Balanced Lineup(线段树水题)

题目大意:给定n个值,执行q次查询,输出区间最大值和区间最小值的差。 解题思路:维护两颗线段树,一颗维护区间最大值,一颗维护区间最小值即可。 做的时候忘了开4倍数组re了一次,cin、cout超时又tle了一次,可以说很蠢了emmmmmmm #include<iostream> #include<algorithm> #include<cstdio> u...

青鱼的博客 220
上一篇: CodeForces 17E Palisection (回文树)
下一篇: HDU 4027 Can you answer these queries? (线段树)
MrBlankIsAwesome
博客等级 码龄11年 4粉丝 196原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值