package main import . "fmt" import . "os" import bf "bufio" import . "slices" func main() { rd:=bf.NewReader(Stdin) wr:=bf.NewWriter(Stdout) var n,q int Fscan(rd,&n,&q) a:=make([]int,n) b:=make([]int,n) for i:=range a { Fscan(rd,&a[i]) } copy(b,a) Sort(b) for ;q>0;q-- { var x,y int Fscan(rd,&x,&y) x-- y-- if a[x]<=a[y] { Fprintln(wr,0) continue } u,_:=BinarySearch(b,a[x]) v,_:=BinarySearch(b,a[y]) Fprintln(wr,u-v) } wr.Flush() }