#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); map ct; rep(i, 0, n){ cin >> a[i]; ct[a[i]] ++; } vector b = a; // コピー sort(b.begin(), b.end()); // b を小さい順にソート b.erase(unique(b.begin(), b.end()), b.end()); // b から重複を除去する vector res(a.size()); for (int i = 0; i < a.size(); ++i) res[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin(); vector jb (n); rep(i, 0, n){ jb[res[i]] = a[i]; } vector rct (n); rct[0] = ct[jb[0]]; rep(i, 1, n){ rct[i] = rct[i - 1] + ct[jb[i]]; } cerr <<"res:\n";for(auto x: res) cerr << x <<" "; cerr << "\n" ; cerr <<"jb:\n";for(auto x: jb) cerr << x <<" "; cerr << "\n" ; cerr <<"rct:\n";for(auto x: rct) cerr << x <<" "; cerr << "\n" ; rep(i, 0, q){ int x, y; cin >> x >> y; x--; y--; if(res[x] <= res[y]) cout << 0 << endl; else cout <