問題一覧 > 通常問題

No.674 n Consecutive Workdays

レベル : / AI推定難易度 : 1300 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 159
作問者 : nmnmnmnmnmnmnm / テスター : ei1333333
お気に入りにしたユーザー ProblemId : 1601 / 自分の提出
問題文最終更新日: 2026-06-29 01:57:17
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 188 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。