8522: Pandaemonium Asphodelos: The First Circle (Savage)

内存限制:128 MB 时间限制:4 S
题面:传统 评测方式:文本比较 上传者:
提交:3 通过:1

题目描述

Oops, there is something wrong with the Pandaemonium. The friend of Azem, Themis, is just waiting for you to have a look together.

Oh no, rattled Erichthonios, who is the guard of Pandaemonium, misunderstanding you as enemies, starts attacking you. Can you protect yourself and Themis until he calms down?

To simplify the problem, Themis' defending system have nn blocks in a line. All the blocks have a initial weight 0 and the same attribute. Erichthonios will perform following 4 kinds of attack qqtimes:

  • 11 xx cc: Erichthonios uses his chain to connect the xx-th block and all \bf{closest}closest 2c2c blocks, giving them a new attribute (overlapping the origin atrributes of the blocks).
  • 22 xx yy: Erichthonios copies the attribute of xx-th block to yy-th and all yy-th block's \bf{nearby}nearby\bf{continuous}continuous\bf{same\ attribute}same attribute\bf{longest}longest blocks. (A segment of same attribute blocks containing yy-th, and the left adjacent block of the segment has a different attribute or is out of boundary, so as right.)
  • 33 xx vv: Erichthonios makes the weight of all the blocks with the same attribute as xx-th block increase by vv.
  • 44 xx: Erichthonios attacks the defending system. Only if you output the weight of the xx-th block, can you defend it.

Attention: Since you don't know what Erichthonios will do next, there is encoding with the queries. (See the \bf{input}input)

If you couldn't solve this problem, you will be laughed at by Hythlodaeus later. You don't want to be like that, right?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases(1T20). Description of the test cases follows.

The first line contains two integers nn and qq (3n1081q105) -- The number of Themis defending system blocks, and the number of attacks that Erichthonios will perform.

The following qq lines contains Erichthonios' attacks, (initially, last = 0last=0):

  • 1 x' c': contains 3 integers, 1xnfloor1c2n1, actually, x=((x1)last)modn + 1c=((c1)last)mod2n1 + 1.
  • 2 x' y': contains 3 integers, xn1yn, actually, x=((x1)last)modn + 1,y=((y1)last)modn + 1.
  • 3 x v: contains 3 integers, 1xn1v109, actually, x=((x1)last)modn + 1, and there is no encode with v 1v109.
  • 4 x': contains 2 integers, 1xn, actually, x=((x1)last)modn + 1, after you get the AnswerAnswer, don't forget to update, last=Answer and 1 073 741 823.

Where  means bitwise XOR operation, \text{and}and means bitwise AND operation.

It is guaranteed that the sum of n does not exceed 2109 and the sum of q does not exceed 106

输出格式

For each test case:

For each 4-th attack, print one integer in a line --- the weight of the block.

输入样例 复制

1
16 12
3 10 16
4 2
1 1 6
1 5 6
1 9 7
1 15 7
2 2 10
2 2 13
3 1 16
4 16
4 9
4 4

输出样例 复制

16
32
32
16

数据范围与提示

The decoded attacks in example:

3, x = 10 , v = 16

4, x = 2

1, x = 1 , c = 1

1, x = 5 , c = 1

1, x = 9 , c = 2

1, x = 15 , c = 2

2, x = 2 , y = 10

2, x = 2 , y = 13

3, x = 1 , v = 16

4, x = 16

4, x = 9

4, x = 4