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…
题目链接:http://codeforces.com/contest/351/problem/D 题目大意:n个数,col[i]对应第i个数的颜色,并给你他们之间的树形关系(以1为根),有m次询问,每次给出vi,ki,要求找出以点vi为根的子树上出现超过ki次的颜色数. 解题思路:这题显然是可以用莫队写的,只要在开一个数组cnk[i]记录出现次数超过i次的颜色数即可,但是要先进行“将树化为线段的操作”,之前写的一道线段树也用了dfs序的方法使得多叉树化为线段:链接,这里就不多说了.要注意的是使用…
http://codeforces.com/problemset/problem/375/D 树莫队就是把树用dfs序变成线性的数组. (原数组要根据dfs的顺序来变化) 然后和莫队一样的区间询问. 这题和普通莫队有点区别,他需要的不单单是统计区间元素种类个数,是区间元素种类个数 >= k[i]的个数. 考虑最简单的用bit维护,复杂度多了个log 观察到每次只需要 + 1  或者 -1 用一个数组sum[k]表示种类数大于等于k的ans 在numc[val]++之后,sum[numc[val]…
题目链接 http://codeforces.com/blog/entry/43230树上莫队从这里学的,  受益匪浅.. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #i…
[SPOJ]Count On A Tree II(树上莫队) 题面 洛谷 Vjudge 洛谷上有翻译啦 题解 如果不在树上就是一个很裸很裸的莫队 现在在树上,就是一个很裸很裸的树上莫队啦. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<set&…
题意与分析 题意是这样的,给定一颗节点有权值的树,然后给若干个询问,每次询问让你找出一条链上有多少个不同权值. 写这题之前要参看我的三个blog:Codeforces Round #326 Div. 2 E(树上利用倍增求LCA).Codeforces Round #340 Div. 2 E(朴素莫队)和BZOJ-1086(树的分块),然后再看这几个Blog-- 参考A:https://blog.sengxian.com/algorithms/mo-s-algorithm 参考B:https:/…
COT2 - Count on a tree II #tree You are given a tree with N nodes. The tree nodes are numbered from 1 to N. Each node has an integer weight. We will ask you to perform the following operation: u v : ask for how many different integers that represent…
COT2 - Count on a tree II You are given a tree with N nodes. The tree nodes are numbered from 1 to N. Each node has an integer weight. We will ask you to perform the following operation: u v : ask for how many different integers that represent the we…
Dating 随便树上莫队搞一搞就好啦. #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PI…
大概学了下树上莫队, 其实就是在欧拉序上跑莫队, 特判lca即可. #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include <string.h> #incl…