Universal Cup Judging System

Universal Cup

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

一列に $n$ 個の植木鉢が並んでおり、$1$ から $n$ までの番号が付けられています。この列に沿って散水機を設置することができます。各散水機は、その位置 $x$($1$ から $n$ までの整数)と向き(左または右)によって特徴付けられます。

すべての散水機は同じ散水範囲 $L$(非負整数)を共有します。

  • 位置 $x$ にあり右を向いている散水機は、区間 $[x, x + L]$ 内の番号を持つすべての植木鉢に水をやります。
  • 位置 $x$ にあり左を向いている散水機は、区間 $[x - L, x]$ 内の番号を持つすべての植木鉢に水をやります。

番号が $1$ から $n$ までの植木鉢のみが存在します。

最初、散水機は $1$ つもありません。次の $2$ 種類の操作を $q$ 個処理する必要があります:

  • 散水機の追加。 「$1\ d\ x$」の形式の操作は、位置 $x$ に新しい散水機を追加します。 $d = 0$ の場合、散水機は左を向いています。 $d = 1$ の場合、散水機は右を向いています。 同じ位置に複数の散水機を設置しても構いません。操作は時系列順に与えられ、削除操作はありません。
  • 区間クエリ。 「$2\ \ell\ r$」の形式の操作は、次の質問を投げかけます: 現在の散水機の集合を考えます。すべての散水機が同じ範囲 $L$ を持つと仮定します。区間 $[\ell, r]$ 内の番号を持つすべての植木鉢が少なくとも $1$ つの散水機によって水やりされるような最小の整数 $L \ge 0$ を求めてください。区間 $[\ell, r]$ の外側にある散水機が $[\ell, r]$ の内側の植木鉢に水をやるのを助ける場合があることに注意してください。($L$ をどれほど大きくしても)$[\ell, r]$ 内のすべての植木鉢に水をやることができる整数 $L$ が存在しない場合は、このクエリに対して $-1$ を出力しなければなりません。

入力

$1$ 行目には、植木鉢の数と操作の数を表す $2$ つの整数 $n$, $q$ ($1 \le n, q \le 3 \cdot 10^5$) が含まれます。

続く $q$ 行のそれぞれは、処理しなければならない順序で $1$ つの操作を説明します:

  • 「$1\ d\ x$」:位置 $x$ に向き $d$ の散水機を追加する ($d \in \{0, 1\}$, $1 \le x \le n$)。ここで、$d = 0$ は散水機が左を向いていることを意味し、$d = 1$ は右を向いていることを意味します。
  • 「$2\ \ell\ r$」:区間 $[\ell, r]$ に対する最小の範囲 $L$ を質問する ($1 \le \ell \le r \le n$)。

出力

「$2\ \ell\ r$」の形式の各クエリについて、$1$ つの整数を含む行を $1$ 行出力してください:

  • $[\ell, r]$ 内のすべての植木鉢に水がやられるような最小の整数 $L \ge 0$、または
  • 不可能な場合は $-1$。

入出力例

入力例 1

10 11
1 0 6
2 5 8
1 1 3
2 9 10
2 3 9
1 1 8
2 1 9
2 1 8
1 0 4
2 3 7
2 2 9

出力例 1

-1
7
6
5
5
4
4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.