Universal Cup Judging System

Universal Cup

実行時間制限: 4.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓
統計

在 3142 年,泰坦星環深處,大崩塌前人類記憶的最後檔案被封印在克羅諾斯寶庫(Chronos Vault)之中。寶庫的入口由迴響轉盤(Echo Dial)守護,這是一個由排列成單一細絲的 $n$ 個時間環所組成的量子糾纏鎖。每個環都會顯示一個介於 $0$ 到 $m - 1$ 之間的相位值,表示其與宇宙節律的對齊狀態。初始時,第 $i$ 個環顯示的數值為 $a_i$。

迴響轉盤只能透過共振調諧來進行調整,並受以下規則約束:

  • 在單次操作中,你可以選擇任意相位值 $x \in [0, m)$,並同時將目前顯示為 $x$ 的所有環調諧為以下兩者之一:
    • 正向調諧:$x \to (x + 1) \bmod m$,或
    • 反向調諧:$x \to (x - 1) \bmod m$。
  • 此操作會影響整個轉盤中目前在相位 $x$ 共振的每一個環,無論其位置為何。

寶庫的智慧守護者「迴響神諭」(Oracle of Echoes)發出了 $q$ 次診斷試煉。每次試煉皆以一組詢問 $(l, r, v)$ 給出,詢問將位置 $l$ 到 $r$(包含兩端)的所有環皆設定為相位 $v$ 所需的最少共振調諧操作次數。

所有試煉都是假設性的。對於每次詢問,迴響轉盤總是從其原本的初始狀態開始,且不會有任何試煉改變轉盤的實際配置。身為最後一位量子檔案管理員,你的職責是高效率地回答所有 $q$ 個詢問。

輸入格式

第一行包含三個整數 $n, q$($1 \le n, q \le 2 \times 10^5$)與 $m$($1 \le m \le 10^9$)。

第二行包含 $n$ 個整數 $a_1, a_2, \ldots, a_n$($0 \le a_i < m$),代表每個環的初始相位。

接下來的 $q$ 行中,每行包含三個整數 $l, r$($1 \le l \le r \le n$)與 $v$($0 \le v < m$),描述一次診斷試煉。

輸出格式

對於每次詢問,輸出一行包含一個整數,代表在假設轉盤從初始狀態開始且在詢問之間保持不變的情況下,將位置 $[l, r]$ 中的所有環設定為相位 $v$ 所需的最少操作次數。

範例

4 6 7
2 0 2 5
1 4 3
2 4 6
1 3 1
1 3 5
3 4 0
3 3 2
5
4
2
4
4
0

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.