Universal Cup Judging System

Universal Cup

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

設 $B$ 是一個長度為 $M$ 的陣列。$B$ 的分數(score)是滿足以下條件的下標 $i$($2 \le i \le M - 1$)的數量:存在下標 $x$ 和 $y$ 滿足 $1 \le x < i < y \le M$ 且 $2 \cdot B_i > B_x + B_y$。

給你一個長度為 $N$ 的陣列 $A$。

你需要回答 $Q$ 個詢問。

對於每個詢問 $L$ $R$($1 \le L < R \le N, R - L + 1 \ge 3$),求:

$$\sum_{i=L}^{R-2} \sum_{j=i+2}^{R} \text{score}(A_i, A_{i+1}, \dots, A_j)$$

換句話說,求完全包含在 $A_L, A_{L+1}, \dots, A_R$ 內的所有長度至少為 $3$ 的子陣列的分數之和。

輸入格式

輸入格式如下:

T
N Q
A_1 A_2 ... A_N
L_1 R_1
:
L_Q R_Q

資料範圍

  • 所有輸入值均為整數。
  • $1 \le T \le 10^4$
  • $3 \le N \le 5 \times 10^5$
  • $1 \le Q \le 5 \times 10^5$
  • $1 \le L < R \le N$ 且 $R - L + 1 \ge 3$。
  • 保證所有測試用例中 $N$ 的總和不會超過 $5 \times 10^5$。
  • 保證所有測試用例中 $Q$ 的總和不會超過 $5 \times 10^5$。

輸出格式

對於每個詢問,輸出一個整數:完全包含在 $A_L, A_{L+1}, \dots, A_R$ 內的所有長度至少為 $3$ 的子陣列的分數之和。

範例

輸入範例 1

1
5 4
2 5 1 3 4
1 5
2 5
1 4
3 5

輸出範例 1

6
2
2
1

說明

測試用例 1:對於詢問 $[1, 5]$,長度至少為 $3$ 的子陣列有:

  • $[2, 5, 1]$,分數 $= 1$
  • $[5, 1, 3]$,分數 $= 0$
  • $[1, 3, 4]$,分數 $= 1$
  • $[2, 5, 1, 3]$,分數 $= 1$
  • $[5, 1, 3, 4]$,分數 $= 1$
  • $[2, 5, 1, 3, 4]$,分數 $= 2$

因此,答案為 $6$。

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.