P10149 [Ynoi1999] XM66F

Background

![](https://cdn.luogu.com.cn/upload/image_hosting/f05zotfr.png)

Description

Given a sequence $a_1,\dots,a_n$ and $m$ queries. Each query gives $l,r$. For each query, find how many triples $(i,j,k)$ satisfy $l\le i

Input Format

The first line contains two integers $n,m$. The second line contains $n$ integers $a_1,\dots,a_n$. The next $m$ lines each contain two integers $l,r$, representing a query.

Output Format

Output $m$ lines. Each line contains one integer, the answer to each query in order.

Explanation/Hint

Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078. All values are integers. For $100\%$ of the testdata, $1\le a_i\le n$, $1\le l\le r\le n$, and $n,m\le 5\times 10^5$. Translated by ChatGPT 5