//#define _GLIBCXX_DEBUG #include using namespace std; //AtCoder-Library #if __has_include() #include using namespace atcoder; using mint = atcoder::modint998244353; #endif //PBDS-tree #if __has_include() #include #include #include using namespace __gnu_pbds; template using Tree = tree, rb_tree_tag, tree_order_statistics_node_update>; //tree.find_by_order(k) = tree[k] (0-indexed) //tree.order_of_key(k) = tree.lower_bound(k) - tree.begin() //Note: Can only be used for non-multiple sets. #endif #define vec vector #define ll long long #define ull unsigned long long #define vi vec #define vll vec #define vb vec #define vvi vec #define vvll vec #define vvb vec #define vvvi vec #define vvvll vec #define vvvb vec #define pii pair #define pll pair #define pli pair #define pq priority_queue template using spq = priority_queue, greater>; #define eb emplace_back #define pb push_back #define spa " " #define all(x) (x).begin(), (x).end() #define rep(i, l, r) for (int i=(int)(l); i<(int)(r); i++) #define REP(i, l, r) for (int i=(int)(l); i<=(int)(r); i++) #define siz(x) (int)x.size() templatebool chmax(T &a, T b) { if (abool chmin(T &a, T b) { if (b vector Slice(vector A, int l, int r) { assert(0 <= l && l < (int)A.size()); assert(0 <= r && r <= (int)A.size()); vector ret; for (int i = l; i= 0) == (y >= 0)) { return (abs(x) + abs(y)-1)/abs(y); } else { return -(abs(x)/abs(y)); } } ll Floor(ll x, ll y) { assert(y != 0); if ((x >= 0) == (y >= 0)) { return abs(x)/abs(y); } else { return -((abs(x) + abs(y)-1)/abs(y)); } } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const pair &p) { os << p.first << " " << p.second; return os; } template istream &operator>>(istream &is, vector &v) { for(auto &x : v) { is >> x; } return is; } template ostream &operator<<(ostream &os, const vector &v) { for(int i = 0; i < (int)v.size(); i++) { if(i != (int)v.size() - 1) os << v[i] << " "; else os << v[i]; } return os; } template void print(T A, bool f = true) { cerr << A; if (f) cerr << endl; } template void print(pair A, bool f = true) { cerr << "{" << A.first << ", " << A.second << "}"; if (f) cerr << endl; } template void print(vector A, bool f = true) { cerr << "{"; for (int i = 0; i<(int)A.size(); i++) { print(A[i], false); if (i+1 != (int)A.size()) cerr << ", "; } cerr << "}"; if (f) cerr << endl; } #define debug(x) cerr << #x << " = "; print(x) #define debug2(x) cerr << #x << " = "; print(x, false) struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); } } iosetup; struct Edge { int to; int cost; Edge(int to, int cost) : to(to), cost(cost) {} }; const int mod1 = 998244353; const int mod2 = 1000000007; const int inf = 1000010000; const ll INF = 1LL<<60; int main() { int N, Q; cin >> N >> Q; vector A(N); rep(i, 0, N) cin >> A[i]; auto B = A; sort(B.begin(), B.end()); rep(i, 0, Q) { int x, y; cin >> x >> y; x--; y--; int ans = lower_bound(B.begin(), B.end(), A[x]) - lower_bound(B.begin(), B.end(), A[y] + 1); cout << max(ans, 0) << endl; } }