链接 大意: 给定n结点树, 求构造一种染色方案, 使得每个点颜色在[A,Z], 且端点同色的链中至少存在一点颜色大于端点 (A为最大颜色) 直接点分治即可, 因为最坏可以涂$2^{26}-1$个节点, 所以方案一定存在 #include <iostream> #include <algorithm> #include <cstdio> #include <vector> #define REP(i,a,n) for(int i=a;i<=n;++i)…
Ciel the Commander Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 321C64-bit integer IO format: %I64d      Java class name: (Any) Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its na…
题目描述: Ciel the Commander time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected by n - 1 undire…
E. Ciel the Commander Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/322/problem/E Description Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected by n - 1 undirected ro…
树链剖分可以看成是树的边分治,什么是点分治呢? CF322E - Ciel the Commander 题目:给出一棵树,对于每个节点有一个等级(A-Z,A最高),如果两个不同的节点有相同等级的父节点(节点不一定相同),则两个节点的路径上最少有一个比他们两的等级都高的节点.要求输出1~n的等级. 分析:考虑一条链的情况,如果把A放中间,把数列分成两段,对于每一段,中间放B,这样分成了四段,对于每一段继续这样分,显然26个字母可以安放2^26个位置. 对于树这种结构的话,如何安放? 类似于一条链的…
E. Ciel the Commander Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected by n - 1 undirected roads, and for any two cities there always exists a path between them. Fox Ciel needs to assign an officer…
Water Tree CodeForces 343D 树链剖分+线段树 题意 给定一棵n个n-1条边的树,起初所有节点权值为0. 然后m个操作, 1 x:把x为根的子树的点的权值修改为1: 2 x:把x结点到根路径上的点修改为0: 3 x:查询结点x的值. 解题思路 这个因为是在树上进行的操作,所以首先需要把树进行一些转化,比如使用dfs序列转变成一维的,这样方便使用线段树或则树状数组来进行操作.但是因为这里的操作2需要把x节点和它的父节点赋值为0,所以需要树链剖分来进行处理. 关于树链剖分的讲…
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires. Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and…
题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就是比较节点总数和有的数字数比较有限向左边转移. 然后这个异或其实可以利用一个数num与一个一个的x异或然后求异或的mex也是容易的只要判断当前二进制位是1那么左右节点拥有的数字数互换(不用真的互换 只要用转移体现出来就行了).这里的01字典树写法是类似线段树且利用递归的方法. #include <i…
题目链接:http://codeforces.com/contest/626/problem/G 题解:这题很明显买彩票肯定要买贡献最大的也就是说买p[i]*(num[i]+1)/(num[i]+a[i]+1)-p[i]*num[i]/(num[i]+a[i])的最大值,当然这个最大值时随时改变的所以要用线段树来维护,先不考虑加彩票减彩票,可以先一开始for一遍全部的彩票先买好,然后再加彩票的或者减彩票的时候考虑不买那个改买那个.这个就需要在线段树上维护一个买一张获得贡献最大的点和不买那个减掉的…