/* -*- coding: utf-8 -*- * * 2710.cc: No.2710 How many more? - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ /* global variables */ int as[MAX_N], bs[MAX_N]; /* subroutines */ /* main */ int main() { int n, qn; scanf("%d%d", &n, &qn); for (int i = 0; i < n; i++) scanf("%d", as + i); copy(as, as + n, bs); sort(bs, bs + n); while (qn--) { int x, y; scanf("%d%d", &x, &y); x--, y--; int m = 0; if (as[y] < as[x]) { int py = upper_bound(bs, bs + n, as[y]) - bs; int px = lower_bound(bs, bs + n, as[x]) - bs; m = px - py; } printf("%d\n", m); } return 0; }