| GPL 2026 Advanced |
|---|
| Finished |
Regina is helping Hearts2Hearts write the melody for their next song. She has an array $$$a$$$ of $$$n$$$ integers (representing the melody), all equal to $$$0$$$ initially. She must process $$$q$$$ operations of the following three types:
The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the length of the array and the number of operations.
Each of the next $$$q$$$ lines describes an operation, in one of the following forms:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$, and the sum of $$$q$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each operation of the third type, output a single line containing one integer — the answer to that query.
15 92 1 22 3 22 5 43 1 513 1 53 2 42 2 03 1 5
8331
There is just one testcase in this sample.
In this test case, $$$n = 5$$$ and the array starts as $$$[0,0,0,0,0]$$$.
After the first three operations (2 1 2, 2 3 2, 2 5 4), the array is $$$[2,0,2,0,4]$$$, and the query $$$(1,5)$$$ asks for $$$2+0+2+0+4=8$$$.
Then, the operation of the first type then recomputes the array from occurrence counts: the value $$$2$$$ occurs twice (at positions $$$1,3$$$) and the value $$$4$$$ occurs once (at position $$$5$$$), so $$$b_2 = 2$$$, $$$b_4 = 1$$$, and every other $$$b_i = 0$$$. The array becomes $$$[0,2,0,1,0]$$$.
The query $$$(1,5)$$$ now asks for $$$0+2+0+1+0=3$$$, and the query $$$(2,4)$$$ asks for $$$2+0+1=3$$$.
Setting $$$a_2 := 0$$$ leaves the array $$$[0,0,0,1,0]$$$, so the final query $$$(1,5)$$$ asks for $$$0+0+0+1+0=1$$$.
| Name |
|---|


