POJ - 3321
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. Output
For every inquiry, output the correspond answer per line.
Sample Input 3 1 2 1 3 3 Q 1 C 2 Q 1 Sample Output 3 2
|
POJ - 3321 Apple Tree (线段树 + 建树 + 思维转换)
最新推荐文章于 2020-08-19 08:49:06 发布