National Olympiad in Informatics, China, 2008
There is a beautiful fairy tale: Once upon a time in a far away land by the edge of the world, there existed a "Candy Kingdom". This nation is filled with skyscrapers; meanwhile, the little trails, flowers, and grass are all made out of candy. What's more magical is that the sky is filled with rainbow colored candy clouds floating about. Very often, heavy candy rain will pour onto the ground. The red colors are strawberry candy, the yellow colors are lemon, the green colors are mint, the black colors are chocolate, and so on. The children of Candy Kingdom will frequently hold open pouches of all sizes to catch the candy pieces that fall from the sky, bringing them home for their friends to enjoy.
Having a very big sweet tooth, little Z longs to be able to visit this fairy tale kingdom. As the old saying goes, what you think about in the day, you will dream about during the night. So one night, little Z dreamed that he has arrived in Candy Kingdom. He discovered that at any given moment, all of the clouds in the sky will have different colors. These different colored clouds continuously drop candies of corresponding colors. What's even more interesting is that all of the clouds are in constant back and forth motion. There's no harm in imagining that there are borders to the sky, which is why the clouds just happen to be moving back and forth between the two borders of the sky. During each unit of time, a cloud moves one unit of distance either to the left or to the right. When a cloud hits the left border of the sky, it will change its direction and start moving to the right; when a cloud completely moves past the right border of the sky, it will change its direction and start moving to the left.
We may as well think of the sky as a Cartesian coordinate plane, where clouds are represented by line segments (which may degenerate to points):
In the figure above, we set the left border of the sky to be
Little Z noticed that new clouds will continuously form in the sky
(during some time, at some starting position, moving in some direction),
and some clouds after moving for a certain time will disappear from the
sky. While clouds are in motion, candy will continuously fall from them.
Little Z decided to bring many bags to catch the falling candy. Bags
have unlimited capacities, but the size of their openings are limited.
For example at time
Input Specification
The first line contains two positive integers
For the following Insert
, Query
, and Delete
. Their formats are as
follows:
Event Type | Input Format | Explanation |
---|---|---|
Insert (A new cloud appears in the sky) |
1 T_i C_i L_i R_i D_i |
At time The data guarantees that at any given moment, the sky will not contain two clouds that are the same color. |
Query (Determine how many different colors of candy a bag can catch) |
2 T_i L_i R_i |
At time |
Delete (A cloud disappears from the sky) |
3 T_i C_i |
At time |
Output Specification
For each Query
event, output one line containing one integer — the
number of different colors of candy that can be caught by the
corresponding bag.
Sample Input
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
Sample Output
1
1
0
2
1
Explanation
There are Insert
events, Query
events, and Delete
events.
At time
At time
At time
At time
At time
At time
At time
At time
At time
At time
Constraints
All of the data will satisfy
The data guarantees that Insert
events, let
Test Case | |||
---|---|---|---|
Problem translated to English by .
Comments