{"raw_statement":[{"iden":"background","content":"![](https://cdn.luogu.com.cn/upload/image_hosting/f05zotfr.png)"},{"iden":"statement","content":"给定序列 $a_1,\\dots,a_n$ ，$m$ 次询问，每次询问给出 $l,r$ ，问有多少组 $(i,j,k)$ 满足 $l\\le i<j<k\\le r,\\;a_i=a_k>a_j$ 。"},{"iden":"input","content":"第一行两个整数 $n,m$。\n\n第二行 $n$ 个整数 $a_1,\\dots,a_n$。\n\n接下来 $m$ 行每行两个整数 $l,r$ 表示一个询问。"},{"iden":"output","content":"共 $m$ 行，每行一个整数，依次表示每个询问的答案。"},{"iden":"note","content":"Idea：ccz181078，Solution：ccz181078，Code：ccz181078，Data：ccz181078\n\n所有数值为整数。\n\n对于 $100\\%$ 的数据，满足 $1\\le a_i\\le n$，$1\\le l\\le r\\le n$，$n,m\\le 5\\times 10^5$。\n\n"}],"translated_statement":null,"sample_group":[["10 5\n9 8 5 4 5 1 5 1 5 8\n2 8\n4 9\n7 9\n6 7\n2 3","4\n4\n1\n0\n0"]],"show_order":[],"formal_statement":null,"simple_statement":null,"has_page_source":false}