Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 16180 | Accepted: 4836 |
Description
There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree.
The tree has N forks which are connected by branches. Kaka numbers the forks by 1 to N and the root is always numbered by 1. Apples will grow on the forks and two apple won't grow on the same fork. kaka wants to know how many apples are there in a sub-tree, for his study of the produce ability of the apple tree.
The trouble is that a new apple may grow on an empty fork some time and kaka may pick an apple from the tree for his dessert. Can you help kaka?
Input
The first line contains an integer N (N ≤ 100,000) , which is the number of the forks in the tree.
The following N - 1 lines each contain two integers u and v, which means fork u and fork v are connected by a branch.
The next line contains an integer M (M ≤ 100,000).
The following M lines each contain a message which is either
"C x" which means the existence of the apple on fork x has been changed. i.e. if there is an apple on the fork, then Kaka pick it; otherwise a new apple has grown on the empty fork.
or
"Q x" which means an inquiry for the number of apples in the sub-tree above the fork x, including the apple (if exists) on the fork x
Note the tree is full of apples at the beginning
Output
Sample Input
3
1 2
1 3
3
Q 1
C 2
Q 1
Sample Output
3
2
题目大意级是说,给你一颗树,最初每个节点上都有一个苹果,有两种操作:修改(即修改某一个节点,修改时这一个节点苹果从有到无,或从无到有)和查询(查询某一个节点他的子树上有多少个苹果)。
由于此题数据比较大(N<=10^5),而且不是标准的二叉树,所以这里我们队每一个节点重新编号,另外为每一个节点赋一个左值和一个右值,表示这个节点的管辖范围。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAv8AAAEBCAIAAABg6V2BAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACajSURBVHhe7d0/rutGtsXhHsgL3yicdNoDMRx4Hk5u1GN4gQGnHXgAxgWcdGTAUcOBYcDoxIaDBm7Qgd8+p5YoapGU+KdIVrF+H1bgq10SyWJR2kfSOf7LnwAAAC2h+wEAAG2h+wEAAG2h+wEAAG2h+wEAAG2h+wEAAG2h+wEAAG2h+wE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AAASUVORK5CYII=" alt="" width="728" height="244" />
上图也就是DFS搜索的时候做标记的过程,这样新的编号为1~6的节点所管辖的范围分别就是[1,6] [2,4] [3,3] [4,4] [5,6] [6,6],其中左边的是左值,右边的是右值,节点1的区间是[1,6],正好这棵子树有6个节点,其他也一样
那我们吧新的节点放进树状数组时
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCADHAagDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD9U6KKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACii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+TKNnmYG7b7ZziuE+Ot9aP4U0YC7gOPEOmEkSrgf6VH710B+C3gwqAdChI9PNk/+KqG5+BXgW8h8qbw5azRb1k2SM7DcpyrYLdQRwe1FwudY2o2W45vbcexlFcx8R9LsPFXhC/swum6leIpns4roo6LcKD5b4bIyD0pw+DHgzH/ACA4h9JZP/iqQ/Bjwacf8SOL/v7J/wDFUXC5b8FW2n+HvB+jaXHJa2gtLSKNoElXCNtG4dfXNbQ1GzDD/TLc/SUVzQ+C3gvOf7Chz6+ZJ/8AFUn/AApTwVzjQYM/9dJP/iqLhc5X4F6naef8Sw13CpHjS/X5nA5EcPFeoDUrIc/bbcjr/rV5/WuWg+B/ge2Mpi8P28ZllM0hR3G+Q4y7YbknA59ql/4Uv4MGP+JHFj2lkH/s1CYXRwngz4d32g/FTUNeutRszp7zXEyN9vLo4kChVihIAhYAfO4J38elevjUbJcf6bbH6SrXNH4LeDCCP7Chwev72T/4qk/4Up4LOM6DAccD95Jx/wCPUXHdGb8NdUsk8R+Owby3B/tgnHmr/wA809671tWsv+f23H1lWuPi+BXgSCaaaPw3axyzNvkZGcFz6n5uTU//AApjwZ/0A4h9JZP/AIqkTocJ4s+Hl9q3xhsNa0zVrWw8PSS2+o6ntul3XF1CjRKCm3IHl+UMhh9zkGvZV1axAP8Aplvx/wBNV/xrlf8AhTHg3PGhxe/72T/4qm/8KV8FndnQYTu6/vJP/iqA0MX9oPUrSX4X3CpdQsf7U0ngSA/8xK2969RBzXEf8KU8E5Unw/bNtdJAHZ2G5GDKcE4OGUEe4rtwMCkIWiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//9k=" alt="" />
那我们求出每一个节点从1~左值的和 和 1~右值的和 他们的差就是这个节点的子树的所有的和(即这棵子树苹果数目)
可以百度下看看树状数组的实现
最后每输入一组数据就进行依次操作就可以了
#include <cstdio>
#include <cstring>
#include <vector>
#define MAXN 100005
#define mem(a) memset(a, 0, sizeof(a))
using namespace std; int TreeArray[MAXN], Left[MAXN], Right[MAXN], Fork[MAXN];
typedef vector<int> Ve;
vector<Ve>Edge(MAXN);
int N,M;
int key; void init()//初始化数组和
{
mem(Left); mem(Right);
mem(Fork); mem(TreeArray);
for(int i=;i<MAXN;i++)Edge[i].clear();
} void DFS(int node)//为每一个node添加一个左值和右值,表示这个节点所
{
Left[node] = key;
for(int i=;i<Edge[node].size();i++)
{
key+=;
DFS(Edge[node][i]);
}
Right[node] = key;
} int LowBit(int x)//返回的是2^k
{
return x & (x ^ (x-));
} void Edit(int k, int num)//修改节点k,如果是添加一个,代入1,删除一个代入-1
{
while(k <= N)
{
TreeArray[k] += num;
k += LowBit(k);
}
} int GetSum(int k)//得到1...k的和
{
int sum = ;
while(k>=)
{
sum += TreeArray[k];
k -= LowBit(k);
}
return sum;
} void ReadDataAndDo()
{
int a,b;
char ch;
for(int i=;i<N;i++)//输入a,b把边存放在容器里面
{
scanf("%d%d", &a, &b);
Edge[a].push_back(b);
}
key = ; DFS();//为每一个节点对应一个左边界和右边界,他自己就存放在左边界里面,而它的管辖范围就是左边界到右边界
for(int i=;i<=N;i++)
{
Fork[i] = ;//最初每个Fork上都有一个苹果
Edit(i,);//同时更新树状数组的值
}
scanf("%d%*c", &M);
for(int i=;i<M;i++)
{
scanf("%c %d%*c", &ch, &b);
if(ch == 'Q')//b的子树就是[Left[b], right[b]]
{
printf("%d\n", GetSum(Right[b]) - GetSum(Left[b]-));
}
else
{
if(Fork[b]) Edit(Left[b],-);//由于每个节点的编号就是它的左值,所以直接修改左节点
else Edit(Left[b],);
Fork[b] = !Fork[b];//变为相反的状态
}
}
} int main()
{
while(~scanf("%d", &N))
{
init();
ReadDataAndDo();
}
return ;
}