QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 128 MB مجموع النقاط: 100

#11999. Candy Rain

الإحصائيات

There is a beautiful fairy tale: at the end of the sky, there is a "Candy Kingdom," where everything from skyscrapers to small flowers and grass is made of candy. Even more magical is that the sky is filled with colorful candy clouds. Soon, candy rain falls densely from the sky: red is strawberry candy, yellow is lemon candy, green is mint candy, black is chocolate candy... At this time, the children of the Candy Kingdom take out pockets of various sizes to catch the candy falling from the sky, to take home and share with their friends.

Little Z, who has a soft spot for candy, longs to visit such a fairy-tale kingdom. As the saying goes, "what you think about by day, you dream about by night." That night, Little Z dreamed that he had arrived in the "Candy Kingdom." He was pleasantly surprised to find that at any given time, all the clouds in the sky have different colors, and clouds of different colors are constantly dropping candy of the corresponding color. Even more interestingly, all the clouds are moving back and forth at a constant speed. We might as well imagine that the sky has boundaries, and all the clouds are moving back and forth between these two boundaries. Every unit of time, a cloud moves one unit to the left or right. When the left edge of a cloud touches the left boundary of the sky, it changes direction and moves to the right; when a cloud moves completely out of the right boundary of the sky, it changes direction and moves to the left.

We can imagine the sky as a Cartesian coordinate system, and the clouds as line segments (a line segment may degenerate into a point):

As shown in the figure above, let the left boundary of the sky be $0$ and the right boundary be $len$. There are $5$ clouds in the figure, among which the cloud labeled $1$ is just changing direction to move to the right, and the cloud labeled $2$ is just changing direction to move to the left. Ignoring the vertical coordinates of the clouds, they do not affect each other during their movement.

Little Z discovered that some clouds constantly appear in the sky (starting from a certain initial position at a certain time and moving in a certain direction), and some clouds disappear from the sky after a certain period of time. During the movement, candy is constantly falling. Little Z decided to take many pockets to catch the candy. The pocket capacity is infinite, but the size of the pocket opening is limited. For example, at time $T$, Little Z takes a pocket with a coordinate range of $[L, R]$ to catch candy. If there exists a position $x$ in $[L, R]$ where candy of a certain color falls, then it is considered that the pocket can catch candy of this color. In extreme cases, the pocket opening interval may be a point, such as $[0,0]$ or $[1,1]$, but it can still catch candy at the corresponding position. Usually, the total number of candies that can be caught is very large, so Little Z wants to know how many different colors of candy his pocket can catch each time (i.e., the moment he takes out the pocket). The time it takes for the candy to fall is negligible.

Input

The first line of the input file contains two positive integers $n$ and $len$, representing the total number of events and the "boundary" of the sky, respectively.

The next $n$ lines each describe an event. All events occur in the order of input. The first number $k$ ($k = 1, 2, 3$) in each line represents the type of event, corresponding to three types of events: insertion event, query event, and deletion event. The input format is as follows:

Event Type Input Format Description
Insertion Event (A cloud appears in the sky) $1\ T_i\ C_i\ L_i\ R_i\ D_i$ At time $T_i$, a cloud with coordinate range $[L_i, R_i]$ and color $C_i$ appears in the sky. The initial movement direction of the cloud is to the left ($D_i = -1$) or to the right ($D_i = 1$). Satisfies $0 \le L_i \le R_i \le len$, $D_i = -1$ or $1$. The data guarantees that no two clouds of the same color will appear in the sky at any time.
Query Event (Query how many different colors of candy a pocket can catch) $2\ T_i\ L_i\ R_i$ At time $T_i$, Little Z uses a large pocket with a coordinate range of $[L_i, R_i]$ to catch candy. Query how many different colors of candy can be caught. Satisfies $0 \le L_i \le R_i \le len$.
Deletion Event (A cloud disappears from the sky) $3\ T_i\ C_i$ At time $T_i$, the cloud with color $C_i$ disappears from the sky. The data guarantees that there is currently a cloud with color $C_i$ in the sky.

Output

For each query event, the output file should contain a corresponding line, which is the answer to the query, i.e., how many different colors of candy the pocket can catch.

Examples

Input 1

10 10 
1 0 10 1 3 -1 
2 1 0 0 
2 11 0 10 
2 11 0 9 
1 11 13 4 7 1 
2 13 9 9 
2 13 10 10 
3 100 13 
3 1999999999 10 
1 2000000000 10 0 1 1

Output 1

1 
1 
0 
2 
1

Note

There are 10 events in total, including 3 insertion events, 5 query events, and 2 deletion events. At time 0, a cloud of color 10 appears in the sky, with an initial position of $[1, 3]$ and moving to the left. At time 1, a pocket with range $[0, 0]$ can catch candy of color 10 (cloud position is $[0, 2]$). At time 11, a pocket with range $[0, 10]$ can catch candy of color 10 (cloud position is $[10, 12]$). At time 11, a pocket with range $[0, 9]$ cannot catch candy of color 10 (cloud position is $[10, 12]$). At time 11, a cloud of color 13 appears in the sky, with an initial position of $[4, 7]$ and moving to the right. At time 13, a pocket with range $[9, 9]$ can catch two different colors of candy: color 10 (cloud position is $[8, 10]$) and color 13 (cloud position is $[6, 9]$). At time 13, a pocket with range $[10, 10]$ can only catch candy of color 10 (cloud position is $[8, 10]$), and cannot catch candy of color 13 (cloud position is $[6, 9]$). At time 100, the cloud of color 13 disappears from the sky. At time 1999999999, the cloud of color 10 disappears from the sky. At time 2000000000, a cloud of color 10 appears in the sky again, with an initial position of $[0, 1]$ and moving to the right.

Constraints

For all data, $0 \le T_i \le 2000000000$, $1 \le C_i \le 1000000$. The data guarantees that $\{T_i\}$ is a non-decreasing sequence, i.e., $T_1 \le T_2 \le \dots \le T_{n-1} \le T_n$. For all insertion events, let $P_i = R_i - L_i$, where $P_i$ represents the length of each cloud.

Data ID $n$ $len$ $P_i$ Data ID $n$ $len$ $P_i$
1 20 10 $\le len$ 6 150000 1000 $\le 3$
2 200 100 $\le len$ 7 200000 1000 $\le 3$
3 2000 1000 $\le len$ 8 100000 1000 $\le len$
4 100000 10 $\le len$ 9 150000 1000 $\le len$
5 100000 100 $\le 2$ 10 200000 1000 $\le len$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.