using System.Linq; using static System.Math; using System; public class P { public int id { get; set; } public int d { get; set; } public int p { get; set; } } public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var q = int.Parse(line[1]); line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, q, a); } static void getAns(int n, int q, int[] a) { var ps = new P[n]; for (int i = 0; i < n; i++) ps[i] = new P { id = i, d = a[i] }; ps = ps.OrderBy(x => x.d).ToArray(); for (int i = 0; i < n; i++) ps[i].p = i; ps = ps.OrderBy(x => x.id).ToArray(); var ans = new int[q]; for (int i = 0; i < q; i++) { string[] line = Console.ReadLine().Trim().Split(' '); var xx = int.Parse(line[0]) - 1; var yy = int.Parse(line[1]) - 1; ans[i] = Max(0, ps[xx].p - ps[yy].p - 1); } Console.WriteLine(string.Join("\n", ans)); } }