hdu 4251 划分树

SiC双向车载充电器技术解析与V2G应用 碳化硅(SiC)功率器件凭借其高击穿电场强度、优异热导率和低开关损耗特性,正在重塑电力电子系统的设计边界。作为第三代半导体材料的代表,SiC MOSFET通过降低80%的开关损耗,使车载充电器(OBC)效率突破96.5%。在双向能量转换架构中,图腾柱PFC与CLLC谐振变换器的组合实现了ZVS软开关,配合三维集成散热方案使功率密度达54W/in³。这些技术进步直接支撑了V2G(车辆到电网)应用场景,使电动车成为虚拟电厂(VPP)的关键单元。通过智能充放电策略优化,电池循环寿命可提升至4000次以上,为电力市 阅读详情

The Famous ICPC Team Again

Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1155    Accepted Submission(s): 561


Problem Description
When Mr. B, Mr. G and Mr. M were preparing for the 2012 ACM-ICPC World Final Contest, Mr. B had collected a large set of contest problems for their daily training. When they decided to take training, Mr. B would choose one of them from the problem set. All the problems in the problem set had been sorted by their time of publish. Each time Prof. S, their coach, would tell them to choose one problem published within a particular time interval. That is to say, if problems had been sorted in a line, each time they would choose one of them from a specified segment of the line.

Moreover, when collecting the problems, Mr. B had also known an estimation of each problem’s difficultness. When he was asked to choose a problem, if he chose the easiest one, Mr. G would complain that “Hey, what a trivial problem!”; if he chose the hardest one, Mr. M would grumble that it took too much time to finish it. To address this dilemma, Mr. B decided to take the one with the medium difficulty. Therefore, he needed a way to know the median number in the given interval of the sequence.
 

Input
For each test case, the first line contains a single integer n (1 <= n <= 100,000) indicating the total number of problems. The second line contains n integers xi (0 <= xi <= 1,000,000,000), separated by single space, denoting the difficultness of each problem, already sorted by publish time. The next line contains a single integer m (1 <= m <= 100,000), specifying number of queries. Then m lines follow, each line contains a pair of integers, A and B (1 <= A <= B <= n), denoting that Mr. B needed to choose a problem between positions A and B (inclusively, positions are counted from 1). It is guaranteed that the number of items between A and B is odd.
 

Output
For each query, output a single line containing an integer that denotes the difficultness of the problem that Mr. B should choose.
 

Sample Input
5 5 3 2 4 1 3 1 3 2 4 3 5 5 10 6 4 8 2 3 1 3 2 4 3 5
 

Sample Output
Case 1: 3 3 2 Case 2: 6 6 4

题意:

给你一串数字表示题目的难度,题目已经按时间顺序排好,每次找出时间在[s,t]之间,
且难度为中间值的题目,而且保证了给的查找范围是奇数,所以变成了每次查找[s,t]中,
第(t-s)/2+1大的难度为多少




#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)
{
    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)
        return tree[dep][l];
     int mid = (L+R)>>1;

     int cnt = toleft[dep][r]-toleft[dep][l-1]; 
     if(cnt >= k)
     {   
         int lpos = L+toleft[dep][l-1]-toleft[dep][L-1];
         int rpos = lpos+cnt-1;
         return query(L,mid,lpos,rpos,dep+1,k);
     }
     else
     {  
         int rpos = r+toleft[dep][R]-toleft[dep][r];
         int lpos = rpos-(r-l-cnt);
         return query(mid+1,R,lpos,rpos,dep+1,k-cnt);
     }
 }


 int main()
 {
     int n,m;
     int cas = 1;
     while(scanf("%d",&n) != EOF)
     {
         memset(tree,0,sizeof(tree));
         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);
         scanf("%d",&m);
         int l,r;
         printf("Case %d:\n",cas++);
         while(m--)
         {
             scanf("%d%d",&l,&r);
             int k =(r-l)/2+1;
             printf("%d\n",query(1,n,l,r,0,k));
         }
     }
     return 0;
 }



AI脸部替换Roop-Unleashed,一键整合包教程 Roop-Unleashed是一个无须训练模型的深度伪造工具,专为图像和视频的面部替换而设计。它通过简洁的浏览器界面提供用户友好且跨平台的使用体验,无论用户是业余爱好者还是专业人士,都能快速上手。它无需复杂的设置即可实现高效的处理和转换,使图像和视频的编辑变得更加轻松和便捷。 阅读详情

相关推荐

Windows下Colmap编译安装全攻略:从Boost到CUDA的避坑指南

本文详细介绍了在Windows系统下编译安装Colmap三维重建工具的完整流程与实战经验。针对Boost库版本兼容性、CUDA与Visual Studio的版本匹配等常见难题提供了具体的避坑指南和解决方案,帮助开发者高效完成从环境配置到最终部署的全过程。

weixin_28235513的博客 198

hdu4251-划分树

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4251 DescriptionWhen Mr. B, Mr. G and Mr. M were preparing for the 2012 ACM-ICPC World Final Contest, Mr. B had collected a large set of...

测试 339

信号完整性分析学习--16--传输线效应

传输线效应 说到传输线效应,大多数人都会想到一个经验法则,那就是: “当互连线的长度大于1/6倍的信号上升时间的空间延伸时,互连线就体现出传输线效应。” 上升时间越小越容易体现传输线效应。 由此可见,同一根互连线,它是否体现传输线效应,要看它要传输什么样的信号。下图所示,一根延时为15ps的互连线,当它传输上升时间为60ps的信号时就会体现传输线效应;当它传输上升时间为180ps的信号时就不体现传输线效应。

qq_29476769的博客 7272

hdu4251(划分树)

The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 696    Accepted Submission(s): 335 Problem Description Whe

晓风残月xj 1005

卫星图像检测,分割,跟踪,超分辨率,数据集调研,以及论文笔记

目标检测,针对物体有很多类如桥,烟囱,罐子等,有静态图像下的检测,也就是图像源头多来自谷歌地图,但是前后帧没有任何联系,并且谷歌地图相对来说比较清楚,难度小一点,也有粗粒度以及较细粒度的检测,然后卫星视频的数据集较少,则可以通过前后帧的联系来辅助检测,并且卫星帧基本上只对车,船,飞机,火车进行检测,没有进行细粒度的检测即将车辆分类为卡车,皮卡,小轿车,但是关船,则可以分类为货船以及军舰,因为目前的卫星视频中小车实在太少了,难以进行更细粒度的检测。luojia 三号卫星。

zhangzhao147的博客 4706

抖音短连接v.douyin.com/xxx 如何生成?

最近公司有个需求,在抖音里如何宣传自己的网站,并且不要有拦截域名的提示,截图如下。 通过ida反编译抖音的app后,将下载后的ipa文件用解压缩软件(如7zip等)解压,从解压后的目录Payload/Aweme.app/找到Aweme可执行文件,拖入ida进行反编译,ida可以检测objective-c语法。 然后进入主题,既然是聊天发消息,就尝试在ida里搜索"message",看看能否找到对...

kakuapi的博客 3万+

HDU 4251 划分树

/* 划分树:解题类型单一,给出10^5个点,给你 q 个查询,每次查询出[l,r] 中第 k 大的值。 划分树: 主系列 4 3 2 5 6 7 8 1 9 排序后 1 8 3 6 5 4 7 2 9 中位数是 5 划左

好久不见 1110

告别Vivado自带编辑器!手把手教你用Sublime Text 4 + Icarus Verilog搭建FPGA开发环境(Windows 10/11)

本文详细介绍如何在Windows 10/11系统下,使用Sublime Text 4和Icarus Verilog搭建高效的FPGA开发环境,替代Vivado自带编辑器。通过配置语法检查、代码高亮和智能补全等功能,提升Verilog开发效率,实现专业级工作流。

weixin_30684743的博客 427

划分树详解 结合例题hdu4251

参考博客:     http://www.notonlysuccess.com/index.php/divide-tree/#more-142     http://blog.csdn.net/fp_hzq/article/details/7993364     http://www.cnblogs.com/pony1993/archive/2012/07/17/2594544.html

hnust_xiehonghao的专栏 1277

直流电源EMI滤波器设计实战:从器件选型到PCB布局的完整指南

本文提供了一份直流电源EMI滤波器的完整实战设计指南。针对EMI噪声超标问题,文章深入剖析了差模与共模噪声的抑制原理,详细讲解了从电路拓扑、核心器件(如X/Y电容、共模电感)的选型计算,到决定性能成败的PCB布局艺术。重点强调了低阻抗路径、干净接地及输入输出隔离等关键布局原则,并分享了常见的调试坑点与排查方法,旨在帮助硬件工程师设计出真正有效的滤波器,确保电源系统通过EMC测试。

q9r0s的博客 641

莆田市C++专项选拔第一轮题4

现在小明同学想要从两堆硬币中各选择一枚硬币,使得两枚硬币的面值之和 不超过 k。不同的硬币组合,就算面值相同,也视为不同的方案。现在他把这些硬币分成了两堆,已知两堆硬币分别有 n 和 m 枚硬币。可选方案有: (1,2), (1,1), (1,1), (5,2), (5,1), (5,1),共 6 种。第一行三个整数 n, m, k,分别表示第一堆硬币的数量,第二堆硬币的数量,以及面值之和的上限。对于30%的数据,1 ≤ n , m ≤ 1000 , 1 ≤ b , c ≤ 1000。

lpstudio的博客 924

hdu4251 划分树

刚学完划分树,然后就直接用模板改了这道题,用模板固然很快啦,还是要自己写一遍的,否则到时候要改细节的地方就麻烦了。 要多熟悉一下呢! 代码: #include #include #include #include using namespace std; const int MAXN=100010; int tree[30][MAXN];//表示每层每个位置的值 int s

amourjun的专栏 755

量化交易 米筐 案例:市值因子选股策略

案例:市值因子的选股策略 1.结果 获得超额收益 年化 49% 2. 从股票中选择市值小的股票 选定财务数据筛选 进行每日调仓(多因子选股调仓 周期频率会小一些) 3. 代码 估值有关指标 # 在沪深300股票中,选出市值比较小的10只股票 # 在这个方法中编写任何的初始化逻辑。context对象将会在你的算法策略的任何方法之间做传递。 def init(context): # 沪深300组合 stocks = index_components('000300.XSHG') # 沪深3

廷益_飞鸟的博客 2311

HDU 4251 The Famous ICPC Team Again 划分树

题目:http://acm.hdu.edu.cn/showproblem.php?pid=4251 题意:给定一个数组,求区间中位数,保证给定区间长度是奇数 思路:划分树求区间中位数 #include #include #include #include using namespace std; const int N = 100010; struct node {

弱智就要多努力 582

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

hdu 4251 划分树(板子题)

题意:给定一个数组,求区间中位数,保证给定区间长度是奇数 思路:划分树求区间中位数 #include #include #include #include using namespace std; #define MAX_SIZE 100005 int sorted[MAX_SIZE];//已经排好序的数据 int toleft[25][MAX_SIZE];

Hallelujah520的博客 384

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

我的划分树(详细 注解)

//题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4251 /* hdu 4251 The Famous ICPC Team Again 别人的代码:(我自己的注解) 注解提供者:GHQ(SpringWater) 自己理解:划分树的思想是将序列按大小,二分位log2(n)层,每一层的信息放在t[d].val[i],(同一层的各部

SprintfWater的专栏 1201

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

划分树模板+模板题--hdu4251

题目链接:点击进入 划分树解决的是快速求区间中第k大值的问题,算法的主要思想是基于线段树和快排的划分方法,可以实现在logn时间内求出任意区间的第k大值。下面这份代码是基于hud4251的一份模板。 代码如下:#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std;

荒野孤鹰 933

hdu 4251 划分树入门题

题意: 给n个数字的数组,m个操作,操作输入fr,to。 每次操作求fr,to范围内的中位数。 解析: 把求区间的第k大数转换成了中位数。 中位数是 第 ((to - fr) >> 1) + 1 大数。 代码: #include #include #include #include #include #include #include #include

渐近自由 463

HDU 4251 划分树

#include #include #include #include #include #include #include #include #include #include using namespace std; #define lc l,m,index<<1 #define rc m+1,r,index<<1|1 #define N 100005 #define ll long long

swust_wbh的专栏 537

Hdu 4251 区间中位数(划分树)

题目链接 The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 796Accepted Submission(s): 388 Problem Description W...

weixin_34348805的博客 412

hdu 4251 The Famous ICPC Team Again(划分树模板)

The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1821    Accepted Submission(s): 854   Problem Description When ...

1999 204

HDU:4251 The Famous ICPC Team Again(划分树)

题意:给一组数字,多次查询求中位数。 思路:划分树。 #include #include #include #include #include #include #include using namespace std; const int maxn=100005; struct DivideTree { int sorted[maxn],dat[20][maxn];

Fighting 571

hdu 4251 The Famous ICPC Team Again--划分树

/* 求区间中间值 可以转化为求kth值 所以用了划分树 直接套用了上一篇的函数 上篇有讲解 */ #include #include using namespace std; const int N=100010; int srted[N]; struct node { int num[N]; int val[N]; }t[40]; int n,m; void build(int l,in

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值