CF633G.Yash And Trees

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yash loves playing with trees and gets especially excited when they have something to do with prime numbers. On his 20th birthday he was granted with a rooted tree of nn nodes to answer queries on. Hearing of prime numbers on trees, Yash gets too intoxicated with excitement and asks you to help out and answer queries on trees for him. Tree is rooted at node 11 . Each node ii has some value aia_{i} associated with it. Also, integer mm is given.

There are queries of two types:

  1. for given node vv and integer value xx , increase all aia_{i} in the subtree of node vv by value xx
  2. for given node vv , find the number of prime numbers pp less than mm , for which there exists a node uu in the subtree of vv and a non-negative integer value kk , such that au=p+mka_{u}=p+m·k .

输入格式

The first of the input contains two integers nn and mm ( 1<=n<=100000,1<=m<=10001<=n<=100000,1<=m<=1000 ) — the number of nodes in the tree and value mm from the problem statement, respectively.

The second line consists of nn integers aia_{i} ( 0<=ai<=1090<=a_{i}<=10^{9} ) — initial values of the nodes.

Then follow n1n-1 lines that describe the tree. Each of them contains two integers uiu_{i} and viv_{i} ( 1<=ui,vi<=n1<=u_{i},v_{i}<=n ) — indices of nodes connected by the ii -th edge.

Next line contains a single integer qq ( 1<=q<=1000001<=q<=100000 ) — the number of queries to proceed.

Each of the last qq lines is either 1 v x or 2 v ( 1<=v<=n,0<=x<=1091<=v<=n,0<=x<=10^{9} ), giving the query of the first or the second type, respectively. It's guaranteed that there will be at least one query of the second type.

输出格式

For each of the queries of the second type print the number of suitable prime numbers.

输入输出样例

  • 输入#1

    8 20
    3 7 9 8 4 11 7 3
    1 2
    1 3
    3 4
    4 5
    4 6
    4 7
    5 8
    4
    2 1
    1 1 1
    2 5
    2 4
    

    输出#1

    3
    1
    1
    
  • 输入#2

    5 10
    8 7 5 1 0
    1 2
    2 3
    1 5
    2 4
    3
    1 1 0
    1 1 2
    2 2
    

    输出#2

    2
    
首页