import std, core.bitop; bool chmin(T)(ref T SE, T MI) { if (SE > MI) { SE = MI; return true; } else { return false; } } bool chmax(T)(ref T SE, T MI) { if (SE < MI) { SE = MI; return true; } else { return false; } } int lowerBound(T)(T[] SE, T MI) { int lo = -1, hi = cast(int)(SE.length); while (hi - lo > 1) { int mid = lo + hi >> 1; (SE[mid] < MI ? lo : hi) = mid; } return hi; } int upperBound(T)(T[] SE, T MI) { int lo = -1, hi = cast(int)(SE.length); while (hi - lo > 1) { int mid = lo + hi >> 1; (SE[mid] > MI ? hi : lo) = mid; } return hi; } void main() { int N, Q; readf("%s %s\n", N, Q); auto A = readln.chomp.split.to!(int[]); auto B = A.dup; B = B.sort.uniq.array; foreach (i; 0 .. Q) { int x, y; readf("%s %s\n", x, y); int idx = B.lowerBound(A[--x]); int idy = B.lowerBound(A[--y]); max(0, idx - idy - 1).writeln; } }