J - Association of Cats and Magical Lights Kattis - magicallights (树状数组+dfs序)
2020-12-13 01:43
标签:data sso tab -128 com can belle input data- Rar the Cat((™)) is the founder of ACM (Association of Cats and Magical Lights). This is the story of the founding of ACM. It is the second half of the year again and Rar the Cat((™)) is looking forward to Christmas. When people think of Christmas, Christmas trees will surely come into the picture. This year, Rar the Cat((™)) decides to decorate a Christmas tree with NN LED lights with up to 100 different colours. Each LED light can only have a single colour as Rar the Cat((™)) is too poor to afford more sophisticated models of LED lights. Being a programmer himself, Rar the Cat((™)) LED lights are arranged in a tree formation on the Christmas tree. That being said, each LED light can be represented as a node and the wires between 22 LED lights can be represented as an edge. The whole formation consists of NN nodes fully connected by N−1N−1 edges. The nodes are labelled from 11 to NN and each node can hold colour denoted as 11 to 100100. It is noted that each LED is connected to every other LED directly or indirectly by wires and the tree formed is rooted at node 11. Hubert the Cow finds that Rar the Cat((™)) Christmas tree is too boring because it lacks some magical colours. A magical colour in a subtree is defined as a colour whereby there is an odd number of LEDs with that particular colour within the subtree only. In the tree to the right, the subtree of node 11has 33 white nodes and 44 black nodes. As such, white is a magical colour for the subtree of node 11. However, the subtree of node 33 has 11white node and 11 black node, thus the number of magical colour of the subtree of node 33 is 22. In addition, all leaf nodes of the tree have 11magical colour by definition. In order to improve on his Christmas tree decorations, Rar the Cat((™)) intends to modify the colours of the LED lights on the tree. However, he does not know how to count how many magical colours there are. Your task, is now to answer how many magical colours there are in a subtree requested by Rar the Cat((™)). This will be done in between Rar the Cat((™))modifications. There will be QQ queries and modifications in total. Soon after this, Rar the Cat((™)) Christmas tree with these magical lights become so popular and Rar the Cat((™)) founded ACM to further spread the adoption of such trees worldwide. The first line will consists of 22 integers, NN and QQ. NN will be positive and not more than 300000300000 while QQ will be positive and not more than 10000001000000. NN integers will follow on the next line. The ithith integer will be CiCi. CiCi denotes the colour of node ii and can only range from 11 to 100100 inclusive. The next line will have N−1N−1 integers. The ithith integer will be Pi+1Pi+1, Pi+1Pi+1 denotes the parent node of node i+1i+1. QQ lines will then follow with 22 integers each, KK followed by XX. If KK is 00, then this line represents a query for how many magical colours are there in the subtree of node XX. If KK is an integer between 11 and 100100, then it means that the colour of node XX is changed to colour KK. For each query when K=0K=0, output in one line: the number of magical colours in the subtree of XX (inclusive). J - Association of Cats and Magical Lights Kattis - magicallights (树状数组+dfs序) 标签:data sso tab -128 com can belle input data- 原文地址:https://www.cnblogs.com/cherish-lin/p/11006957.htmlInput
Output
Sample Input 1
Sample Output 1
10 5
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
0 1
0 4
1 4
0 1
0 4
10
7
8
7
Sample Input 2
Sample Output 2
7 7
1 2 2 1 1 2 1
1 1 1 2 2 3
0 1
0 2
0 3
0 4
0 5
0 6
0 7
1
1
2
1
1
1
1
#include
文章标题:J - Association of Cats and Magical Lights Kattis - magicallights (树状数组+dfs序)
文章链接:http://soscw.com/essay/24108.html