Universal Cup Judging System

Universal Cup

حد الوقت: 2 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

有一排共 $n$ 個花盆,編號由 $1$ 到 $n$。你可以喺呢排花盆隔離放置灑水器。每個灑水器由佢嘅位置 $x$(一個介乎 $1$ 同 $n$ 之間嘅整數)同埋方向(向左或者向右)嚟描述。

所有灑水器共用相同嘅灑水範圍 $L$(一個非負整數)。

  • 位於位置 $x$ 而且指向右邊嘅灑水器可以淋到編號喺區間 $[x, x + L]$ 入面嘅所有花盆。
  • 位於位置 $x$ 而且指向左邊嘅灑水器可以淋到編號喺區間 $[x - L, x]$ 入面嘅所有花盆。

只有編號介乎 $1$ 同 $n$ 之間嘅花盆先至存在。

最初,一個灑水器都冇。你需要處理 $q$ 個屬於以下兩種類型嘅操作:

  • 插入灑水器。 形如「$1\ d\ x$」嘅操作會喺位置 $x$ 插入一個新嘅灑水器。 如果 $d = 0$,灑水器指向左邊。 如果 $d = 1$,灑水器指向右邊。 同一個位置可以放置多個灑水器。操作按時間順序畀出,而且冇刪除操作。
  • 區間查詢。 形如「$2\ \ell\ r$」嘅操作會提出以下問題: 考慮目前嘅灑水器集合。假設所有灑水器都具有相同嘅範圍 $L$。請搵出最小嘅整數 $L \ge 0$,使得區間 $[\ell, r]$ 入面嘅每個花盆都至少被一個灑水器淋到。請注意,喺區間 $[\ell, r]$ 以外嘅灑水器亦都可以幫手淋到 $[\ell, r]$ 入面嘅花盆。如果唔存在任何整數 $L$ 可以令 $[\ell, r]$ 入面嘅所有花盆都被淋到(無論 $L$ 有幾大),你必須對呢個查詢輸出 $-1$。

輸入格式

第一行包含兩個整數 $n$ 同 $q$($1 \le n, q \le 3 \cdot 10^5$),分別代表花盆嘅數量同操作嘅數量。

接落嚟嘅 $q$ 行,每行按必須處理嘅順序描述一個操作:

  • 「$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$」嘅查詢,輸出單獨一行,包含一個整數:

  • 令 $[\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.