CodeForces 622C Not Equal on a Segment】的更多相关文章

题目链接: http://codeforces.com/problemset/problem/622/C 题意: 给定序列,若干查询,每个查询给定区间和t,输出区间内任意一个不等于t的元素的位置. 分析: 最初没看样例直接钦定输出每个不等于t的元素位置,结果怎么想都是n2复杂度的,后来看了样例才发现是输出任意一个.. 对于一个区间,如果区间最大值和最小值相等,那么该区间元素值全部相同,那么我们维护区间的最大最小值,然后判断是否均等于t,若不等,输出最大值或最小值的位置即可,若相等, 则该区间所有…
预处理p[i],p[i]表示:[p[i],i]这段闭区间上所有数字都是a[i] 询问的时候,如果xi==a[ri]并且p[ri]<=li,一定无解 剩下的情况都是有解的,如果xi!=a[ri],那么输出ri,否则输出p[ri]-1. 另外,看到有大牛博客说可以用线段树,大致是这样的: 线段树保存区间最大值与最小值, 如果询问的区间上最小值==最大值,那么无解: 剩下的情况都是有解:如果xi不等于最小值,那么输出最小值位置:如果xi不等于最大值,那么输出最大值位置. #include <stdi…
C. Not Equal on a Segment time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi. For th…
C. Not Equal on a Segment 题目连接: http://www.codeforces.com/contest/622/problem/C Description You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi. For the i-th query find any position pi (li ≤ pi …
C. Not Equal on a Segment time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi. For th…
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it conta…
传送:http://codeforces.com/gym/101612 题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的k的答案. 注意这k步不一定是连续的. 分析: 对于每个数,可以有两种操作: 1. 先将有倍数的数变成它们的最大倍数,而且按照出现次数比较少的先变. 2. 将所有数都变成lcm,而且按照出现次数比较少的先变. 数组f[i]代表,操作i次的最小种类数.对于每一次操作,取min. #include<bi…
http://codeforces.com/contest/1029/problem/A You are given a string tt consisting of nn lowercase Latin letters and an integer number kk. Let's define a substring of some string ss with indices from ll to rr as s[l…r]s[l…r]. Your task is to construct…
题目链接: http://codeforces.com/problemset/problem/622/C 题目大意: 给定一个长度为n(n不超过200000)的序列,有m(m不超过200000)次询问,第i次询问一个区间[li,ri]内是否存在一个数不等于一个给定值x.如果存在,就输出这个数的位置,否则输出-1. 解题思路: 预处理一个数组p[n].p[i]表示从位置i向左一直到位置0,第一个不等于a[i]的数的位置.可以以o(n)的复杂度通过对递推实现.具体来说就是首先令p[0]=-1,然后从…
题意:给你个序列,你可以给某个数加上2的幂次,问最少多少次可以让所有的数相等. 思路(官方题解):我们先给序列排序,假设bit(c)为c的二进制数中1的个数,假设所有的数最后都成为了x, 显然x >= a[n],那么最后的总花费为Σbit(x - a[i]).不妨假设x = t + a[n], b[i] = a[n] - a[i], 那么问题转化为了求Σbit(t + b[i])的最小值.我们假设最后取得最小值的数是x.我们假设已经知道了填充x的低k - 1位的最小花费,我们来考虑填充第k位.我…