思考题 in ancient Chinese
Orange Boy Can You Solve It Out? / 神犇，解乎？
On 2019 Sept 21, I took part in AGC038 with Orange Boy. Happily, I went out to see the moon, round and clear, the sky, pure and sunny, so Orange Boy said:"Today is such a happy day, why don't we play pebbles?" Everyone agrees.
So there are N piles of pebbles, the i-th pile contains Ai pebbles. Orange Boy asks me:"How many interval L,R can you find, so that after sorting the elements from L to R, the whole array will become sorted too?" That's hard, so can you solve it?
Example / 例
Constriants / 规