Professional Documents
Culture Documents
Ants and sugar
Ants and sugar
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
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.
In this sample input, the operations and the answer to the question for each k are as follows.