POJ 2104 K-th Number——————主席树模板,区间第k大

线性分类器(Linear Classifier) 线性分类器 如上图所示,这是二维空间中的一个数据集,如果他正好能够被一条直线分成两类,那么我们称它为线性可分数据集,这条直线就是一个线性分类器。 在三维空间中,如果数据集线性可分,是指能够被一个平面分为两类。 在一维空间中,所有的点都在一条直线上,如果线性可分。可以理解为它们能够被一个点分开。 这里的直线、平面、点被分为决策边界。 一个 m 维空间中的数据集,如果能够被一个超平面一分为二,那么这个数据集就是线性可分的,这个超平面就是决策边界。 例如,这是二维平面上的一条直线, 它可以把平面切分成两 阅读详情

K-th Number

Time Limit: 20000MS Memory Limit: 65536K
Total Submissions: 77307 Accepted: 27874
Case Time Limit: 2000MS

Description

You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order statistics in the array segment.
That is, given an array a[1…n] of different integer numbers, your program must answer a series of questions Q(i, j, k) in the form: “What would be the k-th number in a[i…j] segment, if this segment was sorted?”
For example, consider the array a = (1, 5, 2, 6, 3, 7, 4). Let the question be Q(2, 5, 3). The segment a[2…5] is (5, 2, 6, 3). If we sort this segment, we get (2, 3, 5, 6), the third number is 5, and therefore the answer to the question is 5.

Input

The first line of the input file contains n — the size of the array, and m — the number of questions to answer (1 <= n <= 100 000, 1 <= m <= 5 000).
The second line contains n different integer numbers not exceeding 109 by their absolute values — the array for which the answers should be given.
The following m lines contain question descriptions, each description consists of three numbers: i, j, and k (1 <= i <= j <= n, 1 <= k <= j - i + 1) and represents the question Q(i, j, k).
Output

For each question output the answer to it — the k-th number in sorted a[i…j] segment.

Sample Input

7 3
1 5 2 6 3 7 4
2 5 3
4 4 1
1 7 3

Sample Output

5
6
3

Hint

This problem has huge input,so please use c-style input(scanf,printf),or you may got time limit exceed.

模板题,求区间第k大

#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>

using namespace std;
/*
求区间第k大
poj - 2104
*/

const int MAXN = 1e5+7;
int n, m, cnt, root[MAXN], a[MAXN], x, y, k;
struct node{int l, r, sum;} T[MAXN*40];
vector<int> v;
int getid(int x) { return lower_bound(v.begin(), v.end(), x)-v.begin() + 1;}

void update(int l, int r, int &x, int y, int pos) {// T[y] 是上一版本的, T[x] 是这一版本的
        T[++cnt] = T[y]; T[cnt].sum++; x = cnt;
        if(l == r) return ;
        int mid = (l+r)>>1;
        if(mid >= pos)  update(l, mid, T[x].l, T[y].l, pos);
        else            update(mid+1, r, T[x].r, T[y].r, pos);
}
int query(int l, int r, int x, int y, int k) {
        if(l == r)      return l;
        int mid = (l+r)>>1;
        int sum = T[T[y].l].sum - T[T[x].l].sum;
        if(sum>=k)      return query(l, mid, T[x].l, T[y].l, k);
        else            return query(mid+1, r, T[x].r, T[y].r, k - sum);
}

int main() {
        scanf("%d %d",&n, &m);
        for(int i=1;i<=n;++i)   scanf("%d",&a[i]), v.push_back(a[i]);
        sort(v.begin(),v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        for(int i=1;i<=n;++i)   update(1,n,root[i],root[i-1],getid(a[i]));
        for(int i=1;i<=m;++i) {
                scanf("%d %d %d",&x,&y,&k);
                printf("%d\n",v[query(1, n, root[x-1], root[y], k) - 1]);
        }
        return 0;
}

手把手教你学simulink(13.2)--构建一个单相并网逆变器Simulink仿真模型 基于Simulink的单相并网逆变器项目的详细仿真实例。这个项目将重点放在逆变器的详细建模、最大功率点跟踪(MPPT)控制策略、并网控制和仿真分析上。我们将使用MATLAB/Simulink来构建整个系统,并通过具体的代码和模块来实现各个功能。 阅读详情

相关推荐

告别迷茫!手把手教你用ArcGIS+GTB搞定生态源地MSPA分析(附避坑指南)

本文详细介绍了如何使用ArcGIS和GTB进行生态源地MSPA分析的全流程,包括软件安装、数据预处理、参数设置、结果可视化和常见问题排查。特别针对ArcGIS和GTB组合使用时的常见问题提供了避坑指南,帮助研究者高效完成生态规划任务。

weixin_30756499的博客 435

POJ2104_K-th number

题意: 给n个数,m次询问s,t,k,每次问[s, t]区间的第k大数 思路: 暴力: 排一次序,然后对于每次的询问[s, t],从头开始找那些在[s, t]的数(需要提前记录在原数组的下标),并用cnt计数,当cnt=k时就是该区间的第k大数。 #include <cstdio> #include <cstring> #include <algorithm> ...

CY05627的博客 360

C语言由scanf(“%d“,)非法输入字符造成的死循环及其解决方案

声明:此文章仅作为C语言学习历程中的思路整理,用于解决入门阶段较为浅显的问题,如有错误还请指正。 现象描述: 代码要求实现用户输入1或2,通过scanf("%d",&a)读取这个值,从而判断分属于1或2的两种情况。输入非1,2的数字都应该返回"Invalid Number!",并且要求重新输入数字。 while(a!=1&&a!=2) { printf("Invalid Number!\n"); printf("Enter the number:"); scan

weixin_49764077的博客 8719

POJ 2104 Kth Number 可持续化权值线段树-主席树

K-th NumberTime Limit: 20000MS Memory Limit: 65536KTotal Submissions: 65894 Accepted: 23205Case Time Limit: 2000MSDescriptionYou are working for Macrohard company in data structures department. After ...

Uniontake 391

jlink v9刷固件修改序列号来修复弹窗

jlink v9弹窗警告修复j

weixin_40500627的博客 9367

第四章 自定义组件、动画

第三章 自定义组件、动画 (一)自定义View 1.1) onMeasure:对当前View的尺寸进行测量 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) widthMeasureSpec和heightMeasureSpec包含测量模式和尺寸大小 int widthMode = MeasureSpec....

Stay Hungry Stay Foolish 求知若饥 虚心若愚 8132

POJ2104 Kth Number —— 主席树

题目链接:2104 — K-th Number Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structu...

zhaohaibo的博客 426

C#报表,使用微软rdlc模板,生成Excel, PDF, Word, Image文件,使用自定义对象做数据集不连接数据库

我项目是用vs2017 建的,.NET farmwork 4.7.2 这种报表可以用于任何模式的应用,web,桌面,因为这只是生成一个文件或者文件流 步骤比较详细啰嗦,其中有讲到rdlc怎么新建设计,如果已经会设计rdlc了的可以直接跳到底部看代码的执行结果, 底部还有源码下载链接,百度盘 首先控制台安装报表包 新建rdlc 报表 建立rdlc里要用的数据模型 模型建完,或者修改都要重新...

qq_35955916的博客 5203

POJ2104Kth Number

整体二分模板题, 有些细节需要注意 #include<cstdio> #include<cctype> #include<climits> #include<algorithm> #include<cstring> using namespace std; inline int read() { ...

dk810510的博客 180

ADS入门学习笔记——射频振荡器的设计

振荡器是射频系统中的基本部件之一,可以将直流功率转换为射频功率,在特定的频率点建立起稳定的正弦振荡,成为所需的射频信号源。

weixin_42126696的博客 8950

Pytorch入门教程

Pytorch学习总结:1.张量Tensor 张量是一种特殊的数据结构,与数组和矩阵非常相似。在PyTorch中,我们使用张量对模型的输入和输出以及模型的参数进行编码。 张量类似于NumPy的ndarray,除了张量可以在 GPU 或其他硬件加速器上运行。事实上,张量和NumPy数组通常可以共享相同的底层内存,从而无需复制数据。...

专注大数据与人工智能技术分享,欢迎私信加群互相学习! 4万+

poj2104&&hdu2665kth number【主席树入门题+讲解】

又是卡了一天的知识点,(其实是看不下去下午上网来着,(⊙﹏⊙)b)昨天差点找人问带有懒惰标记的线段树和主席树的区别与联系,多亏憋住了……主席树里面存储的某数字出现的次数,而线段树大多数储存数值,也不好说谁好谁不好,毕竟前者主要处理区间内与个数有关系的问题,比如说区间第k小、区间内不重复数字个数等等,这些线段树都做不了,据说修改主席树时要用树状数组,那不就成了树套树?omg    说几个孙大神的课

MissZhou要努力 1114

第150篇 激光雷达点云分割——地面分离、聚类分析和物体提取

本文介绍了点云分割的三种经典几何方法:RANSAC地面分离、欧式聚类和区域生长。RANSAC通过随机采样拟合平面实现地面分割,欧式聚类基于空间距离进行物体分割,区域生长则结合法线信息提升分割精度。文章对比了各种方法的优缺点,提供了参数选择建议,并指出实际项目中常组合使用这些方法。最后给出了面试应答技巧,强调几何方法速度快、可解释性强等优势,适合大多数机器人项目的实时需求。

郑伟强dev的专栏 192

POJ-2104-K-th Number(区间第K大+主席树模板题)

Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able t...

weixin_30248399的博客 112

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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

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

【主席树_模板题】POJ 2104 K-th Number

主席树_模板题【查询区间第k小】

L_X_ 292

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

POJ 2104 K-th Number

POJ 2104 K-th Number 题目链接 Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order sta

旺崽的博客 2674

SAP B1中文培訓教材_SDK

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

K-th Number POJ - 2104 (主席树 | 划分树)(附动态区间主席树模板)

K-th Number POJ - 2104 You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would...

weixin_44090305的博客 1646

主席树模板 [poj2104]K-th Number

K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 40017   Accepted: 13068 Case Time Limit: 2000MS Description You are working for Macrohard c

Vampire 843

poj-2104 K-th Number【主席树模板】

K-th Number Time Limit:20000MS Memory Limit:65536K Total Submissions:71731 Accepted:25541 Case Time Limit:2000MS Description You are working for Macrohard company in data ...

微微风簇浪,散作满河星 508

K-th Number POJ - 2104 (主席树模板)

题目连接:POJ 2104 kth number You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that wo...

zx93的博客 232

POJ2104-K-th Number(静态主席树模板 区间第k小)

题目链接 You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to retur...

QAQ 288

poj2104 K-th Number (区间第K小,主席树 模板题)

题意: 多组案例。 给n和m,表示长度为n的数列,和m个询问 每个询问要求输出区间L-R中第K小的数 分析: 区间第K小模板题, 直接上主席树 code: #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> us...

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 223

K-th Number Poj - 2104 主席树

K-th Number Poj - 2104 主席树 题意 给你n数字,然后有m次询问,询问一段区间内的第k小的数。 解题思路 这个题是限时训练做的题,我不会,看到这个题我开始是拒绝的,虽然题意清晰简单,但是真的不会。限时结束后,学长说这个题是简单的主席树的入门题,我没学过啊。 如果你也没有学过的话,建议看我的另一篇博客,上面有自己的总结和一些博客推荐,就不用自己一个一个找了,点我进去。...

weixin_30715523的博客 173

POJ2104 K-th Number 主席树

题目链接:http://poj.org/problem?id=2104 题目大意:求区间第k小的数。 分析:主席树模板题。 实现代码如下: #include #include #define N 100010 int T[N]; int num[N]; int san[N]; int ls[N*20]; int rs[N*20]; int sum[N*20];

AC_Gibson的专栏 552

poj 2104 K-th Number ———————— 主席树模板

题目链接:poj_2104 K-th Number 首先我们要知道Tree中所存储的东西,Tree.sum是它所代区间中有几个数,Tree.l 是它的左区间所在结点的下标,Tree.r 是它的右区间所在结点的下标。 感觉代码有几个神奇之处: 1. root[i] = root[i-1]; 直接把 [1,i-1] 这课线段树上存储的东西 给了 [1,i] 这颗线段树 , 相当于

leibniz_zhang的博客 444

POJ 2104-K-th Number-主席树模板

Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to...

Nothing_but_Fight的博客 310
上一篇: 图形学实验02——————画直线,椭圆,多边形
下一篇: POJ 2761 Feed the dogs——————区间第K大,主席树
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值