ccpc网赛 hdu6703 array(权值线段树】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=6703 大意:给一个n个元素的数组,其中所有元素都是不重复的[1,n]. 两种操作: 将pos位置元素+1e7 查询不属于[1,r]中的最小的>=k的值 思路:将数组元素排序,根据其下标建立权值线段树,维护下标的最大值. 修改将对应值在线段树中的下标直接改为inf32. 查询时,查[k,n+1]区间内找到第一个下标>r的位置. #include<bits/stdc++.h> #define ll…
Problem Description You are given an array a1,a2,...,an(∀i∈[1,n],1≤ai≤n). Initially, each element of the array is **unique**.Moreover, there are m instructions.Each instruction is in one of the following two formats:1. (1,pos),indicating to change th…
Petya and Array http://codeforces.com/problemset/problem/1042/D time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya has an array aa consisting of nn integers. He has learned partial sums…
题目大意:给出一个n个元素的数组A,A中所有元素都是不重复的[1,n].有两种操作:1.将pos位置的元素+1e72.查询不属于[1,r]中的最小的>=k的值.强制在线. 题解因为数组中的值唯一,且在1到n的范围内,而询问的r和k也在1到n的范围内. 所以对于任意一个被操 作1修改过的值都不会成为询问的答案,而询问的结果也必然在k到n+1的范围内. 因为没有被修改过 值是唯一的,所以可以建立权值线段树,维护权值区间内的值所在下标的最大值.而询问则转化为不小 于k的值里面,下标超过r的最小权值是多…
引子 对hdu6703,首先将问题转化为"询问一个排列中大于等于k的值里,下标超过r的最小权值是多少" 我们采用官方题解中的做法:权值线段树+剪枝 对(a[i],i)建线段树,查询权值线段树的[k,n]中第一个下标超过r的值 代码是这样的 int ask(int l, int r, int root){ int mid = (l+r)>>1; if(mx[root]<=R)return -1; if(l==r){return l;} int ans = -1; if(…
Governing sand 题意 森林里有m种树木,每种树木有一定高度,并且砍掉他要消耗一定的代价,问消耗最少多少代价可以使得森林中最高的树木大于所有树的一半 分析 复杂度分析:n 1e5种树木,并且砍树肯定是从便宜的砍,有区间性,可以考虑线段树,每次枚举一种高度,先把高于其高度的全部砍掉,再砍低于他的使得满足大于一半的条件,砍低于他的肯定是从花费低的开始砍,所以就是一个选前k小的问题,这样就是一颗权值线段树的事情了 坑点:不同种的树木可能高度相同 #include<bits/stdc++.h…
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6464 免费送气球 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 264    Accepted Submission(s): 53 Problem Description 又到了GDUT一年一度的程序设计竞赛校赛的时间啦.同学们只要参加校赛,…
免费送气球 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 566    Accepted Submission(s): 129 Problem Description 又到了GDUT一年一度的程序设计竞赛校赛的时间啦.同学们只要参加校赛,并且每解出一道题目就可以免费获得由ACM协会和集训队送出的气球一个.听到这个消息,JMC也想参加免费…
D. Restore Permutation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each number from 11 to nn exactly on…
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 middl…