Queries Gym - 100741A - 树状数组】的更多相关文章

题意 给一个数列\(a\),定义\(f(l,r)\)为\(b_1, b_2, \dots, b_{r - l + 1}\),\(b_i = a_{l - 1 + i}\),将\(b\)排序,\(f(l,r)\)=\(\sum\limits_{i = 1}^{r - l + 1}{b_i \cdot i}\) 计算\(\left(\sum\limits_{1 \le l \le r \le n}{f(l, r)}\right) \mod (10^9+7)\) 分析 考虑每个数字对答案的贡献,首先每…
Grandpa Giuseppe won a professional pizza cutter, the kind of type reel and, to celebrate, baked a rectangle pizza to his grandchildren! He always sliced his pizzas into pieces by making cuts over continuous lines, not necessarily rectilinear, of two…
A. Queries time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input output standard output Mathematicians are interesting (sometimes, I would say, even crazy) people. For example, my friend, a mathematician, thinks tha…
题目传送门 题目大意: 给定一颗根节点为1的树,有两种操作,第一种操作是将与根节点距离为L的节点权值全部加上val,第二个操作是查询以x为根节点的子树的权重. 思路: 思考后发现,以dfs序建立树状数组,方便查询,不方便修改,以bfs序建立树状数组,方便修改,不方便查询. 在计算子树权重的时候发现,如果我能算出 所有层 属于这棵子树的  点数*对应层需要加上的val,那么就得到了这棵树的总权重.但是显然暴力统计点数会超时,于是我们把用一个分块的想法,对于一层来说,如果这层的总点数小于块的大小,就…
H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description The longest road of the Fairy Kingdom has n milestones. A long-established tradition defines a specific color for milestones in each region, with a…
题目链接:https://codeforces.com/gym/101908/problem/C 题意: 一块正方形披萨,有 $H$ 刀是横切的,$V$ 刀是竖切的,不存在大于等于三条直线交于一点.求最后切出多少片披萨. 题解: 横切和竖切分开考虑,如果横切的直线之间有 $ans_1$ 个交点,竖切的直线之间有 $ans_2$ 个交点,那么最后答案就是 $(H+1)(V+1)+ans_1+ans_2$. 这里求交点个数,是用的一种比较常见的树状数组优化的套路. 还有就是时限比较紧,用vector…
Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is an executive boarding manager in Byteland airport. His job is to optimize the boarding process. The planes in Byteland have s rows, numbered from 1 t…
题目链接  Tree and Queries 题目大意  给出一棵树和每个节点的颜色.每次询问$vj, kj$ 你需要回答在以$vj$为根的子树中满足条件的的颜色数目, 条件:具有该颜色的节点数量至少为$kj$. (莫队居然可以过) 首先转$DFS$序,这样就变成了区间查询. 然后直接套用莫队,求出每次询问状态下的$t[],t[k]$表示当前区间内拥有$k$个节点的颜色数量. 然后统计$t[k] + t[k + 1], ..., t[MAX]$即可,这个过程用树状数组维护. #include <…
CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. 思路:如果按照题意正面去算有每个线段是否包含点,那么时间复杂度是不允许的:如果去算每个点被哪些线段包含,那么去重比较困难.正难则反,因此对于每个查询,选择去求有多少个线段没有覆盖任何一个点,那么答案则为n减所求.用树状数组来统计没有覆盖任何一个点的线段数,大致做法是将临界线段(如x1+1,x2-1)…
You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to n. Then we represent the color of vertex v as cv. The tree root is a vertex with number…