F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Pandaemonium Asphodelos: The First Circle (Savage)

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 438    Accepted Submission(s): 159


Problem Description
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 $n$ blocks in a line. All the blocks have a initial weight 0 and the same attribute. Erichthonios will perform following 4 kinds of attack $q$ times:

- $1$ $x$ $c$: Erichthonios uses his chain to connect the $x$-th block and all $\bf{closest}$ $2c$ blocks, giving them a new attribute (overlapping the origin atrributes of the blocks).
- $2$ $x$ $y$: Erichthonios copies the attribute of $x$-th block to $y$-th and all $y$-th block's $\bf{nearby}$, $\bf{continuous}$, $\bf{same\ attribute}$, $\bf{longest}$ blocks. (A segment of same attribute blocks containing $y$-th, and the left adjacent block of the segment has a different attribute or is out of boundary, so as right.)
- $3$ $x$ $v$: Erichthonios makes the weight of all the blocks with the same attribute as $x$-th block increase by $v$.
- $4$ $x$: Erichthonios attacks the defending system. Only if you output the weight of the $x$-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}$)

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

Input
Each test contains multiple test cases. The first line contains the number of test cases $(1 \le T \le 20)$. Description of the test cases follows.

The first line contains two integers $n$ and $q$ ($3\leq n\leq10^8$, $1\leq q\leq 10^5$) -- The number of Themis defending system blocks, and the number of attacks that Erichthonios will perform.

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

- $1$ $x'$ $c'$: contains 3 integers, $1\leq x'\leq n$, $1 \leq c' \leq \lfloor\frac{n-1}{2}\rfloor$, actually, $x = \big((x' - 1) \oplus last\big) \mod n\ +\ 1$, $c = \big((c' - 1) \oplus last\big) \mod \lfloor\frac{n-1}{2}\rfloor\ +\ 1$.
- $2$ $x'$ $y'$: contains 3 integers, $1\leq x'\leq n$, $1 \leq y' \leq n$, actually, $x = \big((x' - 1) \oplus last\big) \mod n\ +\ 1$, $y = \big((y' - 1) \oplus last\big) \mod n\ +\ 1$.
- $3$ $x'$ $v$: contains 3 integers, $1\leq x'\leq n$, $1 \leq v \leq 10^9$, actually, $x = \big((x' - 1) \oplus last\big) \mod n\ +\ 1$, and there is no encode with $v$, $1 \leq v \leq 10^9$.
- $4$ $x'$: contains 2 integers, $1\leq x'\leq n$, actually, $x = \big((x' - 1) \oplus last\big) \mod n\ +\ 1$, after you get the $Answer$, don't forget to update, $last = Answer\ \text{and}\ 1\ 073\ 741\ 823$.

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

It is guaranteed that the sum of $n$ does not exceed $2\cdot 10^9$ and the sum of $q$ does not exceed $10^6$
 

Output
For each test case:

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

Sample Input
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
 

Sample Output
16 32 32 16
 

Hint

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
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 09:16:45, Gzip enabled