kth

2019牛客多校第七场E Find the median 权值线段树+离散化

匿名 (未验证) 提交于 2019-12-03 00:03:02
Find the median 题目链接: https://ac.nowcoder.com/acm/contest/887/E 题目描述 Let median of some array be the number which would stand in the middle of this array if it was sorted beforehand. If the array has even length let median be smallest of of two middle elements. For example, median of the array \([10,3,2,3,2]\) is 3 (i.e. \([2,2,\underline{3},3,10]\) ). Median of the array [1,5,8,1] is 1 (i.e. \([1,\underline{1},5,8]\) ). At first, you're given an empty sequence. There are N operations. The i-th operation contains two integers \(L_i\) and \(R_i\) . This means that adding \(R_i-L_i+1\) integers

[HDOJ2665] Kth number

匿名 (未验证) 提交于 2019-12-02 23:52:01
Problem Description Give you a sequence and ask you the kth big number of a inteval. Input The first line is the number of the test cases. For each test case, the first line contain two integer n n n and m m m ( n n n , m m m <= 100000), indicates the number of integers in the sequence and the number of the quaere. The second line contains n integers, describe the sequence. Each of following m lines contains three integers s , t , k s, t, k s , t , k . [ s s s , t t t ] indicates the interval and k k k indicates the kth big number in interval [ s s s , t t t ] Output For each test case, output

378. Kth Smallest Element in a Sorted Matrix

守給你的承諾、 提交于 2019-12-02 13:29:23
import java.util.* /** * 378. Kth Smallest Element in a Sorted Matrix * https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/description/ * * Given a n x n matrix where each of the rows and columns are sorted in ascending order, * find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct element. Example: matrix = [ [ 1, 5, 9], [10, 11, 13], [12, 13, 15] ], k = 8, return 13. Note: You may assume k is always valid, 1 ≤ k ≤ n2. * */ class Solution { fun kthSmallest(matrix: Array<IntArray>, k: Int): Int { //set

2019牛客多校第七场E Find the median 权值线段树+离散化

吃可爱长大的小学妹 提交于 2019-11-29 10:20:28
Find the median 题目链接: https://ac.nowcoder.com/acm/contest/887/E 题目描述 Let median of some array be the number which would stand in the middle of this array if it was sorted beforehand. If the array has even length let median be smallest of of two middle elements. For example, median of the array \([10,3,2,3,2]\) is 3 (i.e. \([2,2,\underline{3},3,10]\) ). Median of the array [1,5,8,1] is 1 (i.e. \([1,\underline{1},5,8]\) ). At first, you're given an empty sequence. There are N operations. The i-th operation contains two integers \(L_i\) and \(R_i\) . This means that adding \(R_i-L_i+1\) integers

HDU-6703-array-2019CCPC选拔赛

你离开我真会死。 提交于 2019-11-28 08:52:40
我TM真是一个弟弟。。。 题意: 给出一串1-N的数字 你每次可以把某个位置的值+1000000 或者找一个值,所有a[1]...a[r]序列的数都不能等于这个值,并且这个值>w 当时比赛觉得肯定是树套树,待修区间第K大,一想不会就自闭了。。。 其实反过来想,如果a[1]....a[r]序列的数都不能等于这个值,那么其实我们可以从a[r+1]....a[n]找到第一个值>=w 但是考虑本题带修改,你会发现这个值加的非常大,大于n,那么一旦某个位置加了这个值,这个值就不再产生贡献 相当于把这个值删掉。 我们考虑把这些值保存起来,因为一旦这个值被删掉,那么意味着,它是有可能作为答案的。 我们建立一颗主席树,并实现查询大于>=w的数的个数,以及区间第K小的操作,并把删除的数放入set里面 我们在区间内部查找>=w的个数,如果这个值为0,我们查询删除的数里面是否有比w大的,如果没有的话,答案就是n+1,否则就是set里面第一个大于w的数,可用lower_bound实现 考虑不为0,我们查第r-l+1+num(大于num的个数)这样就能区间内部查到第一个>=w的数字 再在set里面查询第一个>=w的数字,因为可能1-r区间内被删除的数且这个数比r+1到n区间内>=w的数答案更优秀 两者取最小值即可。 #include<iostream> #include<stdio.h> #include