Advertisement
Guest User

dsdsd

a guest
Apr 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.66 KB | None | 0 0
  1. Shashank loves trees and math. He has a rooted tree, TT, consisting of NN nodes uniquely labeled with integers in the inclusive range [1,N][1,N]. The node labeled as 11 is the root node of tree TT, and each node in TT is associated with some positive integer value (all values are initially 00).
  2.  
  3. Let's define FkFk as the kthkth Fibonacci number. Shashank wants to perform 22 types of operations over his tree, TT:
  4.  
  5. UU XX kk
  6. Update the subtree rooted at node XX such that the node at level 00 in subtree XX (i.e., node XX) will have FkFk added to it, all the nodes at level 11 will have Fk+1Fk+1 added to them, and so on. More formally, all the nodes at a distance DD from node XX in the subtree of node XX will have the (k+D)th(k+D)th Fibonacci number added to them.
  7. QQ XX YY
  8. Find the sum of all values associated with the nodes on the unique path from XX to YY. Print your sum modulo 109+7109+7 on a new line.
  9. Given the configuration for tree TT and a list of MM operations, perform all the operations efficiently.
  10.  
  11. Note: F1=F2=1F1=F2=1.
  12.  
  13. Input Format
  14.  
  15. The first line contains 22 space-separated integers, NN (the number of nodes in tree TT) and MM (the number of operations to be processed), respectively.
  16. Each line ii of the N−1N−1 subsequent lines contains an integer, PP, denoting the parent of the (i+1)th(i+1)th node.
  17. Each of the MM subsequent lines contains one of the two types of operations mentioned in the Problem Statement above.
  18.  
  19. Constraints
  20.  
  21. 1≤N,M≤1051≤N,M≤105
  22. 1≤X,Y≤N1≤X,Y≤N
  23. 1≤k≤10151≤k≤1015
  24. Output Format
  25.  
  26. For each operation of type 22 (i.e., QQ), print the required answer modulo 109+7109+7 on a new line.
  27.  
  28. Sample Input
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement