Universal Cup Judging System

Universal Cup

时间限制: 5.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓
统计

لتكن $B$ مصفوفة بطول $M$. تُعرّف نقاط (score) المصفوفة $B$ بأنها عدد الفهارس $i$ ($2 \le i \le M - 1$) بحيث يوجد فهرسان $x$ و $y$ يحققان $1 \le x < i < y \le M$ و $2 \cdot B_i > B_x + B_y$.

تُعطى مصفوفة $A$ بطول $N$.

تحتاج إلى الإجابة عن $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)$$

بعبارة أخرى، أوجد مجموع النقاط عبر جميع المصفوفات الفرعية التي لا يقل طولها عن $3$ والمحتواة بالكامل داخل $A_L, A_{L+1}, \dots, A_R$.

الإدخال

يُعطى الإدخال بالصيغة التالية:

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$.

الإخراج

لكل استعلام، اطبع عددًا صحيحًا واحدًا: مجموع النقاط عبر جميع المصفوفات الفرعية التي لا يقل طولها عن $3$ والمحتواة بالكامل داخل $A_L, A_{L+1}, \dots, A_R$.

مثال

الإدخال 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.