#P9337. [Ynoi2001] 冷たい部屋、一人
[Ynoi2001] 冷たい部屋、一人
Background
If the evening sun shines into the corner of a cold room.
In the corner of an icy room, it is filled with the glow of the sunset.
Even if you get closer, there are no feelings, and there is no betrayal.
No matter how close you get, there are no emotions, and there are no changes.
Today and tomorrow, I am alone, and surely that is something normal.
Even if I am alone from now on, it is just an ordinary thing.
Without any words to exchange, when the day comes to an end.
Even talking cannot change the ending of this day.
For example, how much warmth is “kindness”.
For example, what exactly is gentleness like.
Without even knowing what warmth might be.
Without even knowing how to obtain warmth.
It is not that easy, not that easy.
So, so, it is not that simple.
The distance between hearts.
The distance of the heart.
In the corner of a cold room, staying small as it is.
In the corner of an icy room, just stay small like this.

Problem Description
Given , a sequence , and a permutation of , you need to answer queries.
For each query, given , compute:
$\sum\limits_{i=1}^n\sum\limits_{j=i+1}^n [a_i=a_j]\cdot\prod_{k=i}^j [l\le y_k\le r]$;
where equals when the condition is true, otherwise it equals .
Input Format
The first line contains two integers .
The second line contains integers .
The third line contains integers .
The next lines each contain two integers , representing a query.
Output Format
Output lines, each containing one integer, the answer to the corresponding query.
3 4
1 1 3
2 3 1
1 2
1 3
2 3
1 1
0
1
1
0
Hint
Idea: Ynoi&nzhtl1477, Solution: Ynoi&ccz181078, Code: ccz181078, Data: ccz181078&Terry2022.
For of the testdata, ; ; , and all are distinct; for each query, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5