The value of a node is the product of all the node in its subtree. So how do you update all the parent node when you update the child node ? The original problem is http://mirror.codeforces.com/gym/101466/problem/K.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
The value of a node is the product of all the node in its subtree. So how do you update all the parent node when you update the child node ? The original problem is http://mirror.codeforces.com/gym/101466/problem/K.
Name |
---|
Auto comment: topic has been updated by coding_weeb (previous revision, new revision, compare).
Hint : If you have many continuous SEED queries, how will you solve it?
Oh so I should handle it offline right
Keep a list of SEED queries. For each RAND query, the answer is the product of current Tu and every updates on u's children in this list.
When the list reaches 300 updates, we'll update all the tree with the list in O(n) and clear the list.
This is not a nice way to solve this problem but i think it's easier to understand.
Thank you highly appreciate it.
You can construct euler order of tree, so each rooted subtree can be mapped subarray of the order.
If you don't know, what is euler order of graph, there is small summary about it.
Let's tin[v] is index of 'enter' v at the order and tout[v] is index of 'exit' v at the order. Then all vertices from T(v) are between tin[v] and tout[v] in order and no other vertices are there.
In converts queries:
Segment tree or Fenwick tree can handle these queries easily in O(logN).
But for this problem product can be very-very large. Even number of divisors of product can be much more that 64-bit values.
So what we needed here is formula for number of divisors. Let X = p1a1·p2a2...·pmam, where piai are powers of different primes, It can be shown that number of divisors of X is (a1 + 1)·(a2 + 1)...·(am + 1).
We can see that there is guaranteed that all prime divisors of values in problem are ≤ 13, so there are only 6 different prime divisors could be: (2, 3, 5, 7, 11, 13).
Using this fact, you can solve this problem next way:
Thank you that's very easy to understand.