change b1,b2,… ,bn permits a stretch [l′,r′] to holds its shape if for any pair of integers (x,y) with the end goal that l′≤x
Correct answer will be upvoted else downvoted. Computer science.
change b1,b2,… ,bn permits a stretch [l′,r′] to holds its shape if for any pair of integers (x,y) with the end goal that l′≤x<y≤r′, we have bx<by if and provided that ax<ay.
A change b1,b2,… ,bn is k-comparative if b permits all stretches [li,ri] for all 1≤i≤k to hold their shapes.
Yuu needs to sort out all k-comparable changes for Touko, however it turns out this is an exceptionally hard undertaking; all things considered, Yuu will encode the arrangement of all k-comparable stages with coordinated acylic diagrams (DAG). Yuu likewise authored the accompanying definitions for herself:
A change b1,b2,… ,bn fulfills a DAG G′ if for all edge u→v in G′, we should have bu<bv.
A k-encoding is a DAG Gk on the arrangement of vertices 1,2,… ,n with the end goal that a stage b1,b2,… ,bn fulfills Gk if and provided that b is k-comparative.
Since Yuu is free today, she needs to sort out the base number of edges among all k-encodings for every k from 1 to q.
Input
The principal line contains two integers n and q (1≤n≤25000, 1≤q≤100000).
The subsequent line contains n integers a1,a2,… ,a which structure a stage of 1,2,… ,n.
The I-th of the accompanying q lines contains two integers li and ri. (1≤li≤ri≤n).
Output
Print q lines. The k-th of them ought to contain a solitary integer — The base number of edges among every single k-encoding
Step by step
Solved in 4 steps with 1 images