[POJ2104]K-th Number(区间第k值 记录初始状态)
题目链接:http://poj.org/problem?id=2104
给n个数和m个查询,查询[i, j]内第k小的数是多少。(主席树、划分树那种高大上的姿势叒不会啊QAQ
可以在维护这n个数的同时维护刚刚输入的时候他们的下标,之后预处理排序一次,查询的时候假如初始下标在[i,j]内,那么k自减1,直到k为0。
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 typedef struct Node { 23 int id; 24 int x; 25 Node() {} 26 Node(int ii, int xx) : id(ii), x(xx) {} 27 }Node; 28 29 const int maxn = 111111; 30 int n, m; 31 Node a[maxn]; 32 33 bool cmp(Node x, Node y) { 34 return x.x < y.x; 35 } 36 37 int main() { 38 // freopen("in", "r", stdin); 39 int tmp; 40 while(~scanf("%d %d", &n, &m)) { 41 for(int i = 0; i < n; i++) { 42 scanf("%d", &tmp); 43 a[i] = Node(i+1, tmp); 44 } 45 sort(a, a+n, cmp); 46 while(m--) { 47 int i, j, k, ans = 0; 48 scanf("%d %d %d", &i, &j, &k); 49 for(int s = 0; s < n; s++) { 50 if(a[s].id >= i && a[s].id <= j) k--; 51 if(k == 0) { 52 printf("%d\n", a[s].x); 53 break; 54 } 55 } 56 } 57 } 58 return 0; 59 }
转载于:https://www.cnblogs.com/kirai/p/5226943.html
[POJ2104]K-th Number(区间第k值 记录初始状态)相关推荐
- POJ 2104 K-th Number(区间第k大数)(平方切割,归并树,划分树)
题目链接: http://poj.org/problem? id=2104 解题思路: 由于查询的个数m非常大.朴素的求法无法在规定时间内求解. 因此应该选用合理的方式维护数据来做到高效地查询. 假设 ...
- 【HDU - 2665】Kth number(区间第K大,主席树,模板)
题干: Give you a sequence and ask you the kth big number of a inteval. Input The first line is the num ...
- 动态区间第k小:树状数组套权值线段树
所谓树状数组套权值线段树,就是在树状树组上套权值线段树 (逃) 解析 如何解决静态区间第k小? 使用主席树就ok啦 辣么如何解决动态区间第k小嘞- 我们想想主席树为啥不能解决动态区间第k小 因为如果改 ...
- POJ 2104 K-th Number 主席树(区间第k大)
题目链接: http://poj.org/problem?id=2104 K-th Number Time Limit: 20000MSMemory Limit: 65536K 问题描述 You ar ...
- poj2104(区间第k大+离散化)
题意: 给定一个序列,求[a,b]区间第k大的数字. 思路: 主席树模板题,但是注意数据范围,需要离散化. 代码: #include<cstdio> #include<cstring ...
- 主席树的各类模板(区间第k大数【动,静】,区间不同数的个数,区间=k的个数)...
取板粗 好东西来的 1.(HDOJ2665)http://acm.hdu.edu.cn/showproblem.php?pid=2665 (POJ2104)http://poj.org/probl ...
- hdu 5919--Sequence II(主席树--求区间不同数个数+区间第k大)
题目链接 Problem Description Mr. Frog has an integer sequence of length n, which can be denoted as a1,a2 ...
- K - The Number of Products
K - The Number of Products 题目入口:K - The Number of Products Codeforces:B. The Number of Products 参考网站 ...
- The UVALIVE 7716 二维区间第k小
The UVALIVE 7716 二维区间第k小 /** 题意:给一个n * n的矩阵,有q个查询每次查询r,c,s,k表示已(r,c)为右上角 大小为s的正方形中 第k小的元素n <= 250 ...
最新文章
- 自律到极致-人生才精致:第2期
- 【CSS3】-webkit-margin-before与margin-top
- 计算机编码规则之:Base64编码
- Linux 应用程序开发入门
- classpath*: 和classpath:有什么区别_我们可以从Java“HelloWorld”中学到什么?
- [你必须知道的.NET]第三十五回,判断dll是debug还是release,这是个问题
- linux建立ftp suse_suse开通ftp的实例
- 【概率论】3-4:二维分布(Bivariate Distribution)
- 【物理应用】基于matlab GUI三相配电网实时仿真【含Matlab源码 1047期】
- Proe/Creo元件替换的方法
- ElasticSearch设置字段的keyword属性
- android 我叫mt 插件,叉叉我叫MT助手
- 各种音视频编解码学习详解之 编解码学习笔记(三):Mpeg系列——Mpeg 1和Mpeg 2
- 100脚的STM32F103VE单片机通过FSMC接口读写DS12C887时钟芯片中的寄存器
- 恕我直言,Java四大名著并不一定适合你!
- LAMP平台QQ农场
- 合辑 | 必知的200+基础技术词汇,你知道多少?
- window 下 jdk11安装与环境变量的配置(超级详细)
- SCI科研论文中如何正确自我引用,避免过度自引?
- loj #10095 P1262 间谍网络
热门文章
- 对称加密和非对称加密
- ecs和eks 比较_如何使用Kubernetes,EKS和NGINX为网站设置DNS
- 一天 用户旅程_439天的旅程改变了我的生活
- Xiki:一个开发人员寻求增强命令行界面的能力
- php执行mysql insert,当执行mysql insert 时插入两条是咋回事
- (C++)1002 A+B for Polynomials
- mysql 绑定参数_MySQL 使用 Perl 绑定参数和列
- Python培训教程分享:visual studio编写python怎么样?
- [雪峰磁针石博客]kotlin书籍汇总
- spring data jpa 详解