Universal Cup Judging System

Universal Cup

时间限制: 2 s 内存限制: 1024 MB 总分: 100 可 Hack ✓
统计

有一排共 $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.