CF380B.Sereja and Tree

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Sereja adores trees. Today he came up with a revolutionary new type of binary root trees.

His new tree consists of nn levels, each vertex is indexed by two integers: the number of the level and the number of the vertex on the current level. The tree root is at level 11 , its index is (1,1)(1,1) . Here is a pseudo code of tree construction.

<br></br>//the global data are integer arrays cnt[], left[][], right[][]<br></br><br></br>cnt[1] = 1;<br></br>fill arrays left[][], right[][] with values -1;<br></br>for(level = 1; level < n; level = level + 1){<br></br> cnt[level + 1] = 0;<br></br> for(position = 1; position <= cnt[level]; position = position + 1){<br></br> if(the value of position is a power of two){ // that is, 1, 2, 4, 8...<br></br> left[level][position] = cnt[level + 1] + 1;<br></br> right[level][position] = cnt[level + 1] + 2;<br></br> cnt[level + 1] = cnt[level + 1] + 2; <br></br> }else{<br></br> right[level][position] = cnt[level + 1] + 1;<br></br> cnt[level + 1] = cnt[level + 1] + 1;<br></br> }<br></br> }<br></br>}<br></br>After the pseudo code is run, cell cnt[level] contains the number of vertices on level levellevel . Cell left[level][position] contains the number of the vertex on the level level+1level+1 , which is the left child of the vertex with index (level,position)(level,position) , or it contains -1, if the vertex doesn't have a left child. Similarly, cell right[level][position] is responsible for the right child. You can see how the tree with n=4n=4 looks like in the notes.

Serja loves to make things complicated, so he first made a tree and then added an empty set A(level,position)A(level,position) for each vertex. Then Sereja executes mm operations. Each operation is of one of the two following types:

  • The format of the operation is " 11 tt ll rr xx ". For all vertices level,positionlevel,position (level=t; l<=position<=r)(level=t; l<=position<=r) add value xx to set A(level,position)A(level,position) .
  • The format of the operation is " 22 tt vv ". For vertex level,positionlevel,position (level=t,position=v)(level=t,position=v) , find the union of all sets of vertices that are in the subtree of vertex (level,position)(level,position) . Print the size of the union of these sets.

Help Sereja execute the operations. In this problem a set contains only distinct values like std::set in C++.

输入格式

The first line contains integers nn and mm (1<=n,m<=7000)(1<=n,m<=7000) .

Next mm lines contain the descriptions of the operations. The operation of the first type is given by five integers: 11 tt ll rr xx (1<=t<=n; 1<=l<=r<=cnt[t]; 1<=x<=106)(1<=t<=n; 1<=l<=r<=cnt[t]; 1<=x<=10^{6}) . The operation of the second type is given by three integers: 22 tt vv (1<=t<=n; 1<=v<=cnt[t])(1<=t<=n; 1<=v<=cnt[t]) .

输出格式

For each operation of the second type, print the answer on a single line.

输入输出样例

  • 输入#1

    4 5
    1 4 4 7 1
    1 3 1 2 2
    2 1 1
    2 4 1
    2 3 3
    

    输出#1

    2
    0
    1
    

说明/提示

You can find the definitions that are used while working with root trees by this link: http://en.wikipedia.org/wiki/Tree_(graph_theory)

You can see an example of a constructed tree at n=4n=4 below.

首页