#include #include using namespace std; using namespace atcoder; using ll = long long; #define rep(i, s, n) for(int i = s; i < (int)(n); i++) #define repr(i, s, n) for(int i = ((int)(n) - 1); i >= s; i--) #define sz(x) ((int)(x).size()) #define inf_int (int) (1e9 + 7) #define inf_ll (ll) (1e+18) int main(){ int n, q; cin >> n >> q; vector a (n), b; rep(i, 0, n){ cin >> a[i]; } b = a; sort(b.begin(), b.end()); rep(i, 0, q){ int x, y; cin >> x >> y; x--; y--; if(a[x] < a[y]) cout << 0 << endl; else{ int posa = upper_bound(b.begin(), b.end(), a[y]) - b.begin(); int posb = lower_bound(b.begin(), b.end(), a[x]) - b.begin(); cout << posb - posa << endl; } } }