【线段树】Gym - 101201J - Shopping】的更多相关文章

题意:给定 n 个物品,然后有 m 个人买东西,他们有 x 元钱,然后从 l - r 这个区间内买东西,对于每个物品都尽可能多的买,问你最少剩下多少钱. 析:对于物品,尽可能多的买的意思就是对这个物品价格取模,但是对于价格比我的钱还多,那么就没有意义,对取模比我的钱少的,那取模至少减少一半,所以最多只要60多次就可以结束,为了快速找到第一个比我的钱少的,使用线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000"…
题意:n个数,m次询问,每次给你一个询问v,l,r,问你v%a[l]%a[l+1]%...%a[r]是多少. a%b,结果要么不变,要么至少缩小到a的一半,于是用线段树,每次询问当前区间最靠左侧的小于等于当前数的值是多少,只需不超过log次询问就能使该数模完,就行了. O(n(logn)^2). #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; int n,m; ll mi…
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consisting only of parentheses '(' and ')' is called balanced if it is one of the following. • A string "()" is balanced. • Concatenation of two balance…
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要找一个最小的点集,使得满足这n个区间的条件 Input n 然后li,ri,ci Output 输出最小点集大小 Sample Input 5 3 7 3 8 10 3 6 8 1 1 3 1 10 11 1 Sample Output 6 Hint 题意 题解: 线段树+二分+贪心 首先我们贪心一…
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/problem/F Description I Ilya Muromets is a legendary bogatyr. Right now he is struggling against Zmej Gorynych, a dragon with n heads numbered from 1 to nf…
D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description When selecting files in an application dialog, Vasya noted that he can get the same selection in different ways. A simple mouse click selects a sing…
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11668&courseid=0 题目大意: N个人,每个人有三个能力排名X Y Z,每种能力没有同名次,如果当前的人比在清单上的人中至少有一项能力都要优,则这个人也会被加到清单上. 求最终清单上有几个人.(N<=100000) 题目思路: [线段树] 首先按第三关键字排序,确定一…
题目链接:http://codeforces.com/gym/101466/problem/K 题目: 题意: 给你一棵有n个节点的树,根节点始终为0,有两种操作: 1.RAND:查询以u为根节点的子树上的所有节点的权值的乘积x,及x的因数个数. 2.SEED:将节点u的权值乘以x. 思路: 比赛时少看了因数不大于13这句话,然后本题难度增加数倍,肝了两个小时都没肝出来,对不起队友啊,今天的组队训练赛实力背锅…… 这题一眼线段树,由于是对一棵子树进行处理,因此我们采用常规套路,借助dfs序将子树…
Summer WarsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88994#problem/J Description The mafia is finally resting after a year of hard work and not so much money. Mafianca, the little mascot of the…
Consider a directed graph G of N nodes and all edges (u→v) such that u < v. It is clear that this graph doesn't contain any cycles. Your task is to find the lexicographically largest topological sort of the graph after removing a given list of edges.…