Universal Cup Judging System

Universal Cup

Süre Sınırı: 4 s Bellek Sınırı: 1024 MB Toplam puan: 100 Zorluk: [göster]
İstatistikler

題目描述

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.