Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

The 21st Japanese Olympiad in Informatics (JOI 2021/2022)

Spring Training Camp/Qualifying Trial


March 20–23, 2022 (Komaba, Tokyo)

Contest 3 – Ants and Sugar

Ants and Sugar

JOI-kun is a biologist. He plans an experiment on ants and sugar.


JOI-kun’s experiment takes place on a long straight stick of length 1 000 000 000 (= 109 ). It is placed from
the left to the right. The point on the stick which is located at a distance x from the leftmost point is called the
point of coordinate x.
Now, nothing is placed on the stick. JOI-kun will perform the Q operations. The i-th operation (1 ≤ i ≤ Q) is
specified by the three integers T i , Xi , Ai . They mean as follows.

• If T i = 1, JOI-kun places Ai ants at the point of coordinate Xi .


• If T i = 2, JOI-kun places Ai sugar cubes at the point of coordinate Xi .

Since ants and sugar cubes are very small, it is possible to place some of them at the same point. JOI-kun may
perform several operations at the same point.
The ants used in this experiment have curious properties. Precisely, if JOI-kun claps hands, every ant will do
the following.

• If there is a sugar cube at a distance less than or equal to L from the ant, the ant will choose any one of
them and eat it.

It may happen that several ants eat the same sugar cube at the same time.
For every k (1 ≤ k ≤ Q), JOI-kun wants to know the answer to the following question.

• Assume that JOI-kun claps hands after the k-th operation. What is the maximum possible number of
sugar cubes eaten by at least one ant?

Write a program which, given the operations performed by JOI-kun and the value of L, answers to JOI-kun’s
questions for all k.
Note that JOI-kun does not clap hands actually. Therefore, the positions of the ants do not change, and the
sugar cubes are not eaten.

Input
Read the following data from the standard input. Given values are all integers.

QL
T 1 X1 A1

Ants and Sugar– 1 / 6


The 21st Japanese Olympiad in Informatics (JOI 2021/2022)
Spring Training Camp/Qualifying Trial
March 20–23, 2022 (Komaba, Tokyo)

Contest 3 – Ants and Sugar

T 2 X2 A2
..
.
T Q XQ AQ

Output
Write Q lines to the standard output. The k-th line (1 ≤ k ≤ Q) of output should contain the maximum
possible number of sugar cubes eaten by at least one ant if JOI-kun claps hands after the k-th operation.

Constraints
• 1 ≤ Q ≤ 500 000.
• 1 ≤ L ≤ 1 000 000 000 (= 109 ).
• T i is 1 or 2 (1 ≤ i ≤ Q).
• 0 ≤ Xi ≤ 1 000 000 000 (= 109 ) (1 ≤ i ≤ Q).
• 1 ≤ Ai ≤ 1 000 000 000 (= 109 ) (1 ≤ i ≤ Q).

Subtasks
1. (6 points) Q ≤ 3 000.
2. (16 points) L = 1, Xi ≤ Q − 1, Xi + T i is an even integer (1 ≤ i ≤ Q).
3. (26 points) Q is an even integer, T i = 1 (1 ≤ i ≤ Q/2), T i = 2 (Q/2 + 1 ≤ i ≤ Q).
4. (52 points) No additional constraints.

Sample Input and Output


Sample Input 1 Sample Output 1
4 1 0
1 1 1 1
2 2 1 1
1 3 1 2
2 0 1

In this sample input, the operations and the answer to the question for each k are as follows.

Ants and Sugar– 2 / 6


The 21st Japanese Olympiad in Informatics (JOI 2021/2022)
Spring Training Camp/Qualifying Trial
March 20–23, 2022 (Komaba, Tokyo)

Contest 3 – Ants and Sugar

1. JOI-kun places an ant at the point of coordinate 1.


Assume that JOI-kun claps hands. Since there is no sugar cube, the answer to the question for k = 1 is 0.
2. JOI-kun places a sugar cube at the point of coordinate 2.
Assume that JOI-kun claps hands. Then, the ant of coordinate 1 eats the sugar cube of coordinate 2.
Therefore, the answer to the question for k = 2 is 1.
3. JOI-kun places an ant at the point of coordinate 3.
Assume that JOI-kun claps hands. Then, both of the ants of coordinates 1, 3 eat the sugar cube of
coordinate 2. Therefore, the answer to the question for k = 3 is 1.
4. JOI-kun places a sugar cube at the point of coordinate 0.
Assume that JOI-kun claps hands. The number of sugar cubes eaten by at least one ant becomes maxi-
mum if the ant of coordinates 1 eats the sugar cube of coordinate 0 and the ant of coordinates 3 eats the
sugar cube of coordinate 2. Therefore, the answer to the question for k = 4 is 2.

This sample input satisfies the constraints of Subtasks 1, 2, 4.

Ants and Sugar– 3 / 6


The 21st Japanese Olympiad in Informatics (JOI 2021/2022)
Spring Training Camp/Qualifying Trial
March 20–23, 2022 (Komaba, Tokyo)

Contest 3 – Ants and Sugar

Sample Input 2 Sample Output 2


20 1 0
2 16 778913911 0
1 7 558407445 0
1 1 589762439 74646747
1 17 74646747 74646747
1 1 149104909 778913911
1 15 956697952 1168286902
2 6 389372991 1168286902
2 4 867453845 1168286902
1 15 157353445 1168286902
1 9 846177695 1168286902
1 7 747107163 1693957364
2 10 525670462 2103741597
2 16 478912944 2405475358
2 6 301733761 2405475358
2 12 132966485 2405475358
1 1 748012313 2725982591
2 10 830922632 2725982591
1 19 969484637 2858949076
1 13 370330582 2858949076
1 1 464798040

This sample input satisfies the constraints of Subtasks 1, 2, 4.

Ants and Sugar– 4 / 6


The 21st Japanese Olympiad in Informatics (JOI 2021/2022)
Spring Training Camp/Qualifying Trial
March 20–23, 2022 (Komaba, Tokyo)

Contest 3 – Ants and Sugar

Sample Input 3 Sample Output 3


20 6 0
2 27 12 0
2 9 11 0
1 36 10 4
2 39 4 4
2 14 9 10
2 33 7 10
2 38 20 10
2 0 20 10
2 25 16 13
1 14 3 30
1 13 19 30
2 6 4 32
2 15 6 32
2 33 4 40
1 12 11 41
1 44 1 44
2 17 14 44
2 12 19 44
1 48 18 44
2 30 16

This sample input satisfies the constraints of Subtasks 1, 4.

Ants and Sugar– 5 / 6


The 21st Japanese Olympiad in Informatics (JOI 2021/2022)
Spring Training Camp/Qualifying Trial
March 20–23, 2022 (Komaba, Tokyo)

Contest 3 – Ants and Sugar

Sample Input 4 Sample Output 4


20 268886972 0
1 984472666 733463744 0
1 478477245 94817772 0
1 242536956 330762563 0
1 65794782 319137646 0
1 320548477 937296140 0
1 815011370 938193848 0
1 565184190 917533785 0
1 245417414 534089975 0
1 529908772 977043962 0
1 603891865 700935654 479827216
2 167042244 479827216 1278170671
2 173921297 798343455 2088297397
2 916159596 810126726 2553832704
2 999299355 465535307 2949828263
2 965968070 501768990 2949828263
2 936073643 174976034 3727900335
2 832859952 778072072 3727900335
2 955489596 704853861 4110329327
2 246733786 382428992 4501234333
2 227669861 390905006

This sample input satisfies the constraints of Subtasks 1, 3, 4.

Ants and Sugar– 6 / 6

You might also like