[Codeforces]860E Arkady and a Nobody-men】的更多相关文章

屯一个虚树的板子,顺便总结一下这样的题型. Description 给定一棵n个节点的有根树,在输入数据通过给出每个节点的父亲来表示这棵树.若某个节点的父亲为0,那么该节点即为根.现在对于每个点,询问它的每个祖先的所有深度不超过该节点的儿子的数量的总和. Input 第一行一个整数n.第二行n个整数,表示每个节点的父亲pi. Output 输出一行n个整数,表示每个节点的答案. Sample Input 5 2 3 4 5 0 Sample Output 10 6 3 1 0 HINT 1<=…
大意: 给定有根树, 根节点深度为$1$. 定义$r(a,b)$为$b$子树内深度不超过$a$的节点数$-1$ 定义$z_a$为$a$的所有祖先的$r$之和. 对于所有点求出$z$的值. 一个点$y$对$x$的贡献显然为$dep[lca(x,y)]$, 直接计算是$O(n^2logn)$, 考虑优化. 注意到点$y$对$x$子树内所有点贡献都相同, 我们考虑深度相同的点之间的贡献, 就转化为对下面程序的优化. REP(d,1,n) q[dep[i]].push_back(d); REP(d,1,…
Codeforces 题目传送门 & 洛谷题目传送门 qwq 这题大约是二十来天前 AC 的罢,为何拖到此时才完成这篇题解,由此可见我是个名副其实的大鸽子( 这是我上 M 的那场我没切掉的 F2 哦,u1s1 我上 M 还要多亏那场的 F1 啊( 首先暴力 \(3^nn\) 枚举子集显然是过不去的,否则这题就退化到 F1 了(大雾 考虑用一个容斥的思想,考虑求出答案的后缀和 \(f_i\),其中 \(i\) 是一个长度为 \(n-1\) 的二进制串.形式化地说,\(f_i\) 等于满足以下条件的…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举那个人收到了几次糖i. 最好的情况显然是其他人都只收到i-1次糖. 然后这个人刚好多收了一次糖 也即 (i-1)kx + x <= n 显然x越大越好. 那么直接令\(x=\frac{n}{( (i-1)*k+1)}\)就好 如果x>M了 那么令x = M; 但这个时候. 要判断一下改变之后的x,按照顺序分的时候是否还能满足这个人收到i次糖. 如果不能收到i次糖的话.跳过.不能统计答案. [代码] #include <…
B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem/B Description The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an…
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding - an active marketing strategy, that includes a set of measures to change either the bra…
A. Oath of the Night's Watch time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands,…
A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minut…
题目链接:http://codeforces.com/problemset/problem/1121/A 真·阅读理解 题意就是 有n个人 pi表示他们的强度 si表示他们来自哪个学校 现在Arkady选了K个人 如果这其中有某些人不是他们学校里最强的,你就让这个人自己去一个学校 他就是这个新学校里面最强的 那么就一定会被选上 并且他原学校的最强的也会被选上 也就是 k个人里有哪个人不是最强的就必须多一个学校呗 读题半小时代码几分钟.. 代码如下 #include <cstdio> #incl…
D. High Load 题目连接: http://codeforces.com/contest/828/problem/D Description Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of…