[atAGC052F]Tree Vertices XOR】的更多相关文章

结论 注意到如果$x$周围有偶数个1,对$x$操作显然不会改变$a_{x}$,因此不妨强制操作的点周围要有奇数个1,不难发现此时恰好会改变该点,即令$a_{x}=a_{x}\oplus 1$ 称$\{a_{i}\}$合法当且仅当其能被得到,问题即统计合法序列数 显然操作是可逆的,因此$\{a_{i}\}$合法等价于其能通过操作使得$\forall 1\le i\le n,a_{i}=1$ 结论1:若$\{a_{i}\}$能通过操作得到$\{b_{i}\}$,两者合法性相同 根据操作的可逆性显然成…
CF1055F Tree and XOR 就是选择两个数找第k大对儿 第k大?二分+trie上验证 O(nlognlogn) 直接按位贪心 维护可能的决策点(a,b)表示可能答案的对儿在a和b的子树中选择 所有可能决策点都贡献这一位是0,看是否<=k 然后更新出下一层的决策点 但是空间太小, 所以要滚动 我的方法: 维护trie节点和控制区间,维护每个区间的元素,维护决策点 注意,(a,b)(b,a)算两个.考虑a!=b时候贡献*=2 #include<bits/stdc++.h> #d…
题面 树上路径是可以通过到根的路径和LCA差出来的,所以建立一棵Trie树按位贪心即可......吗? 发现空间并不够,需要我们每层现建,要记录每个数和它异或答案之后在这一层插进去的编号 #include<cstdio> #include<cstring> #include<algorithm> #define lli long long using namespace std; ; int n,rd,ch,tot; lli k,sz,ans,val[N]; ]; in…
定义两点的距离$d(x,y)$为$x$到$y$路径上边权异或和,则两棵树相同当且仅当$\forall 1\le i\le n$,$d(1,i)$相同 新建一个节点0,连边$(0,1)$,初始权值为0,且不能以这条边为对象操作(但操作与1相连的边会影响其) 记$d_{i}=d(0,i)$,考虑一次操作$(x,y)$对$d_{i}$的影响,恰好是交换$d_{x}$和$d_{y}$ 最终,令$a_{i}$为目标树中$d(1,i)$的值,即要求$d_{i}\oplus d_{1}=a_{i}$ 同时,记…
B. Appleman and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are color…
传送门 又是权限题= =,过了NOIp我就要去当一只权限狗! LCT裸题,get到了两个小姿势. 1.LCA操作应该在access中随时updata 2.Link操作可以更简单 void Link(int noda,int nodb){Reverse(noda);t[noda].fa=nodb;} //BZOJ 3282 //by Cydiater //2016.9.16 #include <iostream> #include <cstdio> #include <cstr…
CF462D Codeforces Round #263 (Div. 2) D Codeforces Round #263 (Div. 1) B B. Appleman and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Appleman has a tree with n vertices. Some of t…
Description 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…
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then…
题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input :standard input output:standard output Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices a…