Universal Cup Judging System

Universal Cup

Límite de tiempo: 4 s Límite de memoria: 1024 MB Puntuación total: 100 Dificultad: [mostrar]
Estadísticas

題目描述

Una 同 Kamome 計劃去廣州郊區行山。

山上面由西向東有 $n$ 個觀景點,編號由 $1$ 到 $n$。第 $i$ 個觀景點嘅海拔係 $h_i$。Una 決定揀一個區間 $[l, r]$($1 \le l \le r \le n$),並由第 $l$ 個觀景點行去第 $r$ 個觀景點。

不過,Una 唔鍾意山谷,所以佢唔希望有任何 $l < i < r$ 係一個山谷,即係 $h_{i-1} > h_i < h_{i+1}$。同時,佢覺得平路好悶,所以佢希望對於所有 $l \le i < r$,都有 $h_i \neq h_{i+1}$。如果區間 $[l, r]$ 滿足呢兩個條件,Una 就會好享受呢次旅程。

Kamome 喺行山之前做咗啲資料搜集,查到其中一啲觀景點嘅海拔。佢想知道,如果其餘所有觀景點嘅海拔都係 $[1, m]$ 入面獨立隨機嘅整數,有幾多個唔同嘅區間 $[l, r]$ 可以令 Una 享受呢次旅程。請幫 Kamome 求呢個數量嘅期望值,對 $10^9 + 7$ 取模。

輸入格式

每個測試點包含多組測試數據。第一行包含一個整數 $t$($1 \le t \le 10^5$),表示測試數據嘅組數。接住落嚟係各組測試數據嘅描述。

每組測試數據嘅第一行包含兩個整數 $n, m$($1 \le n \le 10^6$,$\sum n \le 10^7$,$1 \le m \le 10^9$),表示山上面嘅觀景點數量同海拔範圍。

第二行包含 $n$ 個整數 $h_1, h_2, \dots, h_n$($1 \le h_i \le m$ 或者 $h_i = -1$),表示 Kamome 搜集到嘅結果。如果 $h_i \neq -1$,則 $h_i$ 表示觀景點 $i$ 嘅實際海拔;否則,表示 Kamome 搵唔到關於觀景點 $i$ 海拔嘅任何資料,並將佢視作 $[1, m]$ 入面嘅隨機整數。

輸出格式

對於每組測試數據,輸出一個整數,表示令 Una 享受旅程嘅區間 $[l, r]$ 嘅期望數量,對 $10^9 + 7$ 取模。

範例

範例輸入 1

10
4 4
1 4 2 3
3 3
-1 2 -1
4 2
-1 -1 -1 1
4 3
1 -1 -1 3
5 5
-1 2 -1 4 -1
6 4
2 -1 1 -1 -1 1
5 5
1 -1 4 -1 1
8 4
-1 2 -1 -1 2 -1 4 -1
9 7
4 -1 2 -1 -1 6 -1 4 -1
20 20
-1 -1 -1 5 -1 -1 13 -1 10 -1 -1 -1 -1 12 -1 3 -1 -1 -1 18

範例輸出 1

8
666666676
875000012
555555566
872000016
750000017
400000014
554687520
973046972
216066617

範例解釋

對於第一組測試數據,如果 Una 揀區間 $[1, 1], [2, 2], [3, 3], [4, 4], [1, 2], [2, 3], [3, 4]$ 或者 $[1, 3]$,佢就會享受呢次旅程。

對於第二組測試數據,答案係 $\frac{14}{3}$。

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.