hdu-6621 K-th Closest Distance】的更多相关文章

K-th Closest Distance 主席树第二波~ 题意 给你\(n\)个数\(m\)个询问,问\(i\in [l,r]\)计算每一个\(|a_{i}-p|\)求出第\(k\)小 题目要求强制在线\(l = l \oplus ans.r = r \oplus ans.p = p \oplus ans.k = k \oplus ans\)(ans为上次询问的答案) 思路 二分答案\(ans\),找区间\(i\in[l,r], a_{i} \in [p-ans, p+ans]\)里的数量\(…
K-th Closest Distance Time Limit: 20000/15000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1697    Accepted Submission(s): 633 Problem Description You have an array: a1, a2, , an and you must answer for some qu…
HDU6621 K-th Closest Distance HDU2019多校训练第四场 1008(主席树+二分) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6621 题意: 给你n个数,有m次询问 每次问你在区间[l,r]内 第k小的|\(a_i-p\)|是多少 题解: 主席树+二分 每次二分答案 如果p+mid到p-mid的值的个数大于k个的话,mid值就是可行了,然后缩小区间往左找即可 因为保证有解,所以二分出来的mid值就是答案了 que…
题目链接 K-th Closest Distance Problem Description You have an array: a1, a2, , an and you must answer for some queries. For each query, you are given an interval [L, R] and two numbers p and K. Your goal is to find the Kth closest distance between p an…
题目描述 You have an array: a1, a2, , an and you must answer for some queries.For each query, you are given an interval [L, R] and two numbers p and K. Your goal is to find the Kth closest distance between p and aL, aL+1, ..., aR.The distance between p…
K-th Closest Distance 题目传送门 解题思路 二分答案+主席树 先建主席树,然后二分答案mid,在l和r的区间内查询[p-mid, p+mid]的范围内的数的个数,如果大于k则说明这个范围内存在第k小的数,r=mid,否则不存在,l=mid+1. 代码如下 #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; inline int read(){…
传送门 •题意 有 $m$ 次询问,每次询问求 $n$ 个数中, $[L,R]$ 区间距 $p$ 第 $k$ 近的数与 $p$ 差值的绝对值: •题解 二分答案,假设当前二分的答案为 $x$,那么如何判断 $x$ 是否可以呢? 只需判断 $[L,R]$ 区间值在 $[p-x,p+x]$ 的数的个数 $sum$ 是否大于等于 k 即可: 如果 $sum \geq k$,那么,x 大了,需要减小范围,反之,需要增大范围: 如何快速求解 $[L,R]$ 区间值在 $[p-x,p+x]$ 的数的个数呢?…
题意:给一个数组,每次给 l ,r, p, k,问区间 [l, r] 的数与 p 作差的绝对值的第 k 小,这个绝对值是多少 分析:首先我们先分析单次查询怎么做: 题目给出的数据与多次查询已经在提示着我们在用数据结构去解决这个问题,对于常见的处理区间的数据结构首选线段树啦: 我觉得这道题的关键在于此:我们需要去二分答案ans,  为什么呢? 我们这样观察 ,对于 | p-a[i] | <= ans  等于 p-ans<=a[i] <=p+ans   那问题就转化为查询[L,R] 区间里面…
题意: 给你一个数组,q次询问,每次问你[l,r]范围内与p距离第k大的元素的与p的距离,强制在线 思路: 主席树提取出[l,r]内的权值线段树,然后二分与p的距离mid ask该权值线段树里[p-mid,p+mid]的数的个数,使其刚好大于等于k 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #inclu…
Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) Total Submission(s): 3520    Accepted Submission(s): 1247 Problem Description The course of Software Design and Development Practice is objectionable. ZLC is facing…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6621 题目大意:给一个数组,每次给 l ,r, p, k,问区间 [l, r] 的数与 p 的绝对值的第 k小的数是哪个 解题思路:可以二分mid,然后判断在[l,r]区间内是否刚好有k个数大于等于p-mid,小于等于p+mid,判断的话可以直接用主席树,用主席树可以查找出小于等于某个数的个数,找到小于p+mid的个数-小于等于p-mid-1的个数,即为区间[l,r]内小于等于p+mid且大于p-m…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6621 题意为求区间[l,r]内第k小|a[i]-p|的值. 可以二分答案,如果二分的值为x,则判断区间[l,r]内是否有k个数在[p-x,p+x]范围内.所以就用主席树搞一下. #include<iostream> #include<algorithm> #include<cstring> #include<string> #include<cmath&g…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5122 Problem Description Matt's friend K.Bro is an ACMer.Yesterday, K.Bro learnt an algorithm: Bubble sort. Bubble sort will compare each pair of adjacent items and swap them if they are in the wrong or…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5122 解题报告:定义一种排序算法,每一轮可以随机找一个数,把这个数与后面的比这个数小的交换,一直往后判断,直到后面没有比这个数小的,这样称为一轮,现在给定一个长度为n的序列,要你求,至少要经过多少轮,可以使这个序列成为有序的. 由于只能跟后面的数进行比较,所以我只要统计后面的数有比这个数小的数的个数就可以了.从后往前扫一遍,每次更新当前最小的. #include<cstdio> #include&…
K.Bro Sorting Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 2510 Accepted Submission(s): 1174 Problem Description Matt's friend K.Bro is an ACMer. Yesterday, K.Bro learnt an algorithm: Bubble…
Matt's friend K.Bro is an ACMer.Yesterday, K.Bro learnt an algorithm: Bubble sort. Bubble sort will compare each pair of adjacent items and swap them if they are in the wrong order. The process repeats until no swap is needed.Today, K.Bro comes up wi…
lightoj1146 Two men are moving concurrently, one man is moving from A to B and other man is moving from C to D. Initially the first man is at A, and the second man is at C. They maintain constant velocities such that when the first man reaches B, at…
题意 给定 $n$ 个数,接下来有 $q$ 次询问,每个询问的 $l, r, p, k$ 要异或上一次的答案,才是真正的值(也就是强制在线).每次询问,输出 $[l, r]$ 内第 $k$ 小的 $|p-a[i]|$. 分析 通常主席树用来求区间第K大,其实它的实际作用是统计某个区间内值的个数.所以, 对于每次询问,对答案进行二分,对于可能的答案 $x$,对 $R_l \sim  R_r$ 的线段树查找 $[p-x, p+x]$ 的是否为 $k$. 主席树中在值上建立的,这题数据范围为 $10^…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6588 题目大意:求\(\sum_{i=1}^{n}gcd(\left \lfloor \sqrt[3]{i} \right \rfloor,i),\ n\leq 10^{21}\) 题解:考虑对\(\left \lfloor \sqrt[3]{i} \right \rfloor\)分块,将式子转换成\(\sum_{i=1}^{\left \lfloor \sqrt[3]{n} \right \rfl…
题目链接:Click here 大致题意:q次询问,每次询问你区间[L,R]中|p-ai|的值第k小的是多少 Solution: 直接找是很困难的,我们考虑二分答案,那么本题就十分简单了 我们对权值维护一颗主席树,每次只要查询区间[L,R]中权值在[p-mid,p+mid]之的数的个数就行了 Code: #include<bits/stdc++.h> using namespace std; const int N=1e6+1; int n,m,maxn,lst,L,R,k,p,a[N]; i…
题意:给定一个长为n的序列,有m次强制在线的询问,每次询问位置[L,R]中abs(a[i]-p)第k小的值 n,m<=1e5,a[i]<=1e6,p<=1e6,k<=169 思路:主席树外面套个二分 #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pai…
题目大意:给你一堆数,每次询问区间[l,r]中离p第k小的|ai-p| 题解:考虑二分答案,对于每个可能的答案,我们只需要看在区间[l,r]里是否有≥k个比二分的答案还要接近于p的 考虑下标线段树,并将其可持久化,线段树i存储1~i中每个数有几个 因为数比较大,考虑离散化,这样最多1e5个数,可以接受 判断时只需要查找第r棵线段树和第l-1棵线段树的区间[l,r]中位于[p-k,p+k]的数有几个然后将返回的值相减看是否≥k即可,注意这里有一些细节 时间复杂度O(mlog^2n) 代码: #in…
题目链接 题意:n个数,q次查询,查询[l , r] 内, | a[i] - p | 第k大的数 思路:主席树维护下权值大小,二分答案,查询区间[p - mid, p + mid] 的个数 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<map> #include<vector> #include<queue&g…
题意: 有\(n\)个数\(a_1\cdots a_n\),现要你给出\(k\)个不相交的非降子序列,使得和最大. 思路: 费用流建图,每个点拆点,费用为\(-a[i]\),然后和源点连边,和后面非降的数连边,源点和超级源点连一条容量\(k\)的边,跑费用流. 用\(spfa\)费用流\(TLE\),这里因为不会出现负环,所以用\(Dijkstra\)优化. 代码: /******* dijkstra优化费用流模板 *******/ //不能有负环 #include<functional> /…
2019 Multi-University Training Contest 4 http://acm.hdu.edu.cn/contests/contest_show.php?cid=851 1001. AND Minimum Spanning Tree 如果\(n\not =2^x-1\)那么答案为\(0\),可以这么构造: 对于\(i\ne 2^x-1\)把\(i\)连向第一个比\(i\)小的\(j\),并且\(i\&j=0\). 否则\(i\)连向\(i+1\),把这两个点绑在一起就好了…
Special Tetrahedron 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points which are in three-dimensional space(without repetition). Please find out how many distinct Special Tetrahedron among them. A tetrahedron is called Sp…
题解 A AND Minimum Spanning Tree 参考代码: #include<bits/stdc++.h> #define maxl 200010 using namespace std; int n,ans1; ]; int ans[maxl]; inline void prework() { scanf("%d",&n); } inline int find(int x) { ;j<=;j++) ) return mi[j]; } inlin…
在K近邻法(KNN)原理小结这篇文章,我们讨论了KNN的原理和优缺点,这里我们就从实践出发,对scikit-learn 中KNN相关的类库使用做一个小结.主要关注于类库调参时的一个经验总结. 1. scikit-learn 中KNN相关的类库概述 在scikit-learn 中,与近邻法这一大类相关的类库都在sklearn.neighbors包之中.KNN分类树的类是KNeighborsClassifier,KNN回归树的类是KNeighborsRegressor.除此之外,还有KNN的扩展,即…
Distance Queries Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 12950   Accepted: 4577 Case Time Limit: 1000MS Description Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifesty…
Distance Queries Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 12846   Accepted: 4552 Case Time Limit: 1000MS Description Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifesty…