Z - New Year Tree CodeForces - 620E 这个题目还没有写,先想想思路,我觉得这个题目应该可以用bitset, 首先这个肯定是用dfs序把这个树转化成线段树,也就是二叉树. 然后就是一个区间修改和区间查询.这个区间查询时查询这个区间的种类数. 这个之前写过几个题目也是查区间种类数的 G. Yash And Trees 线段树 bitset 20190709 暑训 区间种类数 莫队的学习 莫队和权值线段树应该都是不支持修改的,所以这个题目用不上, 然后就是这个高端压位…
The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree. The New Year tree is an undirected tree with n vertices and root in the v…
E. New Year Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural…
题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) struct node{ long long num, lazy; } tree[ << ]; st…
LINK 题目大意 给你一棵树 让你支持子树染色,子树查询颜色个数,颜色数<=60, 节点数<=4e5 思路 因为颜色数很少,考虑状态压缩变成二进制 然后直接在dfs序上用线段树维护就可以了 //Author: dream_maker #include<bits/stdc++.h> using namespace std; //---------------------------------------------- //typename typedef long long ll…
传送门 •题意 给你一颗 n 个节点的树,每个节点被染上了颜色: 有 m 次操作,每次操作的类型有两种 1 v c : 将以 v 为根的子树的结点全部涂成 c 2 v : 询问以 v 为根的子树的结点中不同颜色的数量 •题解 因为操作的是某个节点对应的子树,所以我们可以通过DFS序获得每一个结点的子树区间. 之后我们就将这个树形的问题转化成了一个线性区间的问题: 然后,就可以用线段树来维护(区间更新,区间查询): 求解某个区间不同颜色的个数要怎么办呢? 刚开始,我在线段树中定义了一个 $set$…
C. Propagating tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n n…
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher’s Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree…
题面 Vasya has a tree consisting of n vertices with root in vertex 1. At first all vertices has 0 written on it. Let d(i,j) be the distance between vertices i and j, i.e. number of edges in the shortest path from i to j. Also, let's denote k-subtree of…
A - Lake Counting POJ - 2386 最最最最最基础的dfs 挂这道题为了提高AC率(糖水不等式 B - Paint it really, really dark gray CodeForces - 717E dfs 待会写题解 C - New Year Transportation CodeForces - 500A 简单的模拟 D - Binary Tree Traversals HDU - 1710 给树的先序中序输出后序 贴下代码 #include <algorith…