After much hard work, you find the North Pole to be more than adequately prepared for the upcoming Christmas. However, when you go to ask Santa about his retirement, he reveals that he had tricked you and only wanted you to do his work for him. Furious, you challenge him to a present-making duel on Christmas Eve, with the winner attaining the title of Santa.
During the duel, you are responsible for making presents for a big city with families numbered to . In this city, there is a hierarchy structure that indicates the prestige of each family. The prestigious family is the most renowned of these families and has every other family somewhere below it. All the other families each have exactly one family directly above them in prestige. At the start, each family has some amount of kids .
To beat Santa, your toy factory must be able to answer the following queries:
1 x v
: Through a Christmas miracle, family gains kids.2 x v
: The kids in family and every family below them on the hierarchy become obsessed with a new toy. However, this new toy can only be manufactured in bundles of . You must count and output the number of families in this group that have a number of kids divisible by .
As spectators begin to gather in the distance, you must now find a way to answer these queries quickly in order to finally realize your dream of becoming Santa.
Input Specification
The first line of input contains two space-separated integers, and .
The next line of input contains space-separated integers, , where and is the family above family .
The next line of input contains space-separated integers, .
The next lines of input each contain three space-separated integers, corresponding to one of the above query types.
Output Specification
For each query of type , output the answer on a separate line.
Constraints
For this problem, you are not required to pass previous subtasks to earn points for a specific subtask.
In all subtasks,
At any point, the number of kids a family has will not exceed .
Subtask 1 [10%]
Subtask 2 [30%]
For all type queries, .
Subtask 3 [60%]
No additional constraints.
Sample Input
8 9
0 3 4 7 8 5 1 7
17420 6186 13022 9244 7696 3496 17956 3528
1 1 1
2 7 4
2 1 3
1 5 3
1 8 4
2 5 1
1 1 4
1 7 3
2 5 8
Sample Output
5
3
2
1
Comments