Universal Cup Judging System

Universal Cup

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

西暦 3142 年、タイタンの環の奥深くで、大崩壊以前の人類の記憶を収めた最後のアーカイブがクロノス・ヴォールト(Chronos Vault)の内部に封印されています。その入口は、単一のフィラメント状に並んだ $n$ 個の時間リングからなる量子もつれ錠「エコー・ダイヤル(Echo Dial)」によって守られています。各リングは宇宙の律動との同調を表す $0$ から $m - 1$ までの範囲の位相値を表示します。初期状態では、$i$ 番目のリングは値 $a_i$ を示しています。

エコー・ダイヤルは以下のルールに従う共鳴調律によってのみ調整できます:

  • 1 回の操作では、任意の位相値 $x \in [0, m)$ を 1 つ選び、現在 $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$ 個のクエリすべてに効率よく答えることです。

入力

1 行目には 3 つの整数 $n, q$($1 \le n, q \le 2 \times 10^5$)および $m$($1 \le m \le 10^9$)が与えられます。

2 行目には、各リングの初期位相を表す $n$ 個の整数 $a_1, a_2, \ldots, a_n$($0 \le a_i < m$)が与えられます。

続く $q$ 行にはそれぞれ、診断試練を表す 3 つの整数 $l, r$($1 \le l \le r \le n$)および $v$($0 \le v < m$)が与えられます。

出力

各クエリについて、ダイヤルが元の状態から始まりクエリ間で変化しないと仮定したとき、位置 $[l, r]$ のすべてのリングを位相 $v$ に設定するために必要な最小操作回数を表す整数を 1 行に出力してください。

入出力例

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.