No.674 n Consecutive Workdays
タグ : / 解いたユーザー数 159
作問者 :
nmnmnmnmnmnmnm
/ テスター :
ei1333333
Problem Statement
A-kun gets work scheduled during the $D$ days from day $0$ to day ${D-1}$.
There is no work before or after the $D$ days, and initially no work is scheduled within the $D$ days either.
From now on, $Q$ work schedules will be added.
The $i$-th work schedule is added in the form of from day $A_i$ to day $B_i$ within the $D$ days.
On a day with at least one work schedule, he always goes to work.
On a day with no work at all, he does not go to work.
For example, if work is scheduled from day 0 to day 3 and there is no work on day 4, that is 4 consecutive workdays.
Each time a work schedule is added, answer the maximum number of consecutive workdays that exist within the $D$ days.
Input
$D$ $Q$
$A_0$ $B_0$
$A_1$ $B_1$
$\vdots$
$A_{Q-1}$ $B_{Q-1}$
$D$ is the number of days in the period. $D$ is an integer. $1 \le D \le 1000000000000000000 = 10^{18}$.
$Q$ is the number of work schedules. $Q$ is an integer. $1 \le Q \le 30000 = 3 \times 10^4$.
$A_i$ and $B_i$ are the days in the i-th instruction. $A_i$ and $B_i$ are integers. $0 \le A_i \le B_i \le {D-1}$.
Output
Each time a work schedule is added, answer the maximum number of consecutive workdays that exist within the $D$ days.
Print a newline at the end of every line of the answer.
Sample
Sample 1
Input
10 3 0 1 6 8 2 7
Output
2 3 9
When work is scheduled from day 0 to day 1, the maximum is 2 consecutive workdays, from day 0 to day 1.
When work is scheduled from day 6 to day 8, the maximum is 3 consecutive workdays, from day 6 to day 8.
When work is scheduled from day 2 to day 7, the maximum is 9 consecutive workdays, from day 0 to day 8.
Sample 2
Input
10 4 3 7 3 5 1 1 4 9
Output
5 5 5 7
Sample 3
Input
1000000000000000000 2 0 999999999999999999 0 999999999999999999
Output
1000000000000000000 1000000000000000000
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。