Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) Total Submission(s): 2811    Accepted Submission(s): 827 Problem Description In this problem we consider a rooted tree with N vertices. The vertices a…
Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) Problem Description In this problem we consider a rooted tree with N vertices. The vertices are numbered from 1 to N, and vertex 1 represents the root…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4358 题意:以1为根节点含有N(N <= 1e5)个结点的树,每个节点有一个权值(weight <= 1e9).之后有m(m <= 1e5)次查询,每次查询以节点u为子树的树中,权值出现k次的权值有多少个? Sample Input 1 3 1 (n,k) 1 2 2 1 2 1 3 3 (m) 2 1 3   Sample Output Case #1: 1 1 1   思路:建好树之后,…
题意:N个节点的有根树,每个节点有一个weight.有Q个查询,问在以u为根的子树中,有恰好出现了K次的weight有多少种. 这是第一次写莫队算法,之前也只是偶有耳闻. 看了别人的代码打的,还是贴上来吧. #pragma comment(linker, "/STACK:1000000000") #include <iostream> #include <cstdio> #include <fstream> #include <algorith…
Boring counting: http://acm.hdu.edu.cn/showproblem.php?pid=4358 题意: 求一棵树上,每个节点的子节点中,同一颜色出现k次 的 个数. 思路: 由于是子树中出现了k次,sum+1.所以增加某种颜色的时候,如果这个颜色+1==k,那么sum++.如果删除的时候这个数+1 == k+1,那么sum--: #include <algorithm> #include <iterator> #include <iostrea…
P2336 [SCOI2012]喵星球上的点名 名字怎么存?显然是后缀自动机辣 询问点到多少个喵喵喵其实就是 查询后缀自动机上parent树的一个子树 于是我们考虑莫队 怎么树上莫队呢 我们用dfs序处理后缀自动机上的parent树 把parent树映射到序列上 于是我们就可以愉快地莫队辣 最后怎么处理每个喵喵喵被点到的次数呢 我们在莫队的时候维护一个$Ls[i]$数组维护颜色$i$的存在时间(显然会被划分为好几段) 当颜色$i$第一次进队(队内本来没有该颜色)时,就记下$Ls[i]$ 当队中最…
Tree and Queries 题意:有一颗以1号节点为根的树,每一个节点有一个自己的颜色,求出节点v的子数上颜色出现次数>=k的颜色种类. 题解:使用莫队处理这个问题,将树转变成DFS序区间,然后就是开一个数据记录下出现次数为k次的颜色数目,查询的时候直接返回这个数组中的对应的值就行了. 注意的就是记得将节点的颜色传递给dfs序对应位置的颜色. 这个忘记了找了好久的bug. 代码: #include<bits/stdc++.h> using namespace std; #defin…
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://acm.hdu.edu.cn/showproblem.php?pid=3887 题意:给出一个有根树,问对于每一个节点它的子树中有多少个节点的值是小于它的. 思路:这题和那道苹果树是一样的,DFS序+树状数组,一开始没想到,用了DFS序+排序,结果超时了.在in和out之间的时间戳是该节点子树的范围,从后往前扫,再删掉大的,这样可以满足值小于该节点的条件. #include <cstdio> #include <cstring> #include <cmath&…
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1的边不一定的树,然后给出问题:询问区间和 或者 节点值更新. HDU 3887: 题意:和POJ 3321的题意差不多,只不过对每个节点询问不包含该节点的区间和 思路:今天才学了下才知道有DFS序这种东西,加上树状数组处理一下区间和 和 节点更新. DFS序大概就是我们在DFS遍历一棵树的时候,在进…