The Astral Express is a special train that traverses the galaxy. The galaxy initially consists of $$$2 \cdot n$$$ planets represented as an array $$$a_1, a_2, \ldots, a_{2 \cdot n}$$$, where the $$$i$$$-th planet initially has a gravitational coefficient of $$$a_i = 1$$$ if $$$i \le n$$$ and $$$a_i = -1$$$ if $$$i \gt n$$$.
The Astral Express moves in steps, and the direction of the movement is determined by its velocity $$$v$$$. At the beginning of each step, if $$$v \gt 0$$$, then the Express moves one index to the right. If $$$v \lt 0$$$, then the Express moves one index to the left. If $$$v = 0$$$, then the crew moves in the direction they moved previously. At the end of each step, if the Express is at position $$$i$$$, then $$$a_i$$$ is added to $$$v$$$. If the Astral Express goes past the bounds of the array, then its journey will end.
Since the galaxy is unstable, the planets are constantly breaking apart and merging. A planet with $$$|a_i| = 2$$$ may split into two adjacent planets with gravitational coefficients of $$$\frac{a_i}{2}$$$, and two identical adjacent planets with $$$a_i = a_{i + 1}$$$ and $$$|a_i|= 1$$$ may merge into a single planet with gravitational coefficient $$$a_i + a_{i + 1}$$$.
The Astral Express crew is curious about how their train will move in this unstable galaxy, so you are given $$$q$$$ queries of $$$3$$$ types:
For example, given $$$n = 3$$$, our initial array will look like $$$[1, 1, 1, -1, -1, -1]$$$, and we can perform an operation "2 2", merging $$$a_2$$$ and $$$a_3$$$ together, resulting in an array of $$$[1, 2, -1, -1, -1]$$$. We can then perform an operation "3 2", splitting $$$a_2$$$ into two elements, resulting in an array of $$$[1, 1, 1, -1, -1, -1]$$$.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 10^5$$$, $$$1 \le q \le 2 \cdot 10^5$$$).
The next $$$q$$$ lines each contain two integers $$$t$$$ and $$$x$$$ ($$$1 \le t \le 3$$$). If $$$t = 1$$$, then it is guaranteed that $$$1 \le x \le 10^9$$$. If $$$t = 2$$$, then it is guaranteed that $$$a_x = a_{x + 1}$$$ and $$$|a_x| = 1$$$. If $$$t = 3$$$, then it is guaranteed that $$$|a_x| = 2$$$.
—
There are $$$20$$$ tests, not including samples. Each test is worth $$$\frac{100}{20}=5$$$ points.
In the $$$i$$$-th test, $$$n \le \max(2, \min(10^5, 10^{\lfloor \frac{i}{2} \rfloor})))$$$.
For each query of type $$$1$$$, output a single integer denoting the number of steps the Astral Express will take before their journey ends, or $$$-1$$$ if the journey will go on forever.
3 71 22 51 22 11 23 41 3
9 11 -1 4
1000 202 4173 4172 6951 9853 6951 9951 2402 15942 5283 15931 7942 32 10442 3731 1143 3731 6801 4241 8911 69
30761 10976 943401 370359 988509 539948 817182 204906 997710
—
Problem Idea: oursaco
Problem Preparation: oursaco
Occurrences: Advanced K
| Name |
|---|


