#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n, q; cin >> n >> q; vector a(n); rep(i, n) cin >> a[i]; vector p2p(n); { vector> tmp; rep(i, n) tmp.push_back({ a[i], i }); sort(tmp.begin(), tmp.end()); rep(i, n) { if (tmp[i - 1].first == tmp[i].first) { p2p[tmp[i].second] = p2p[tmp[i - 1].second]; } else { p2p[tmp[i].second] = i; } } } while (q--) { int x, y; cin >> x >> y; --x, --y; cout << max(0, p2p[x] - p2p[y] - 1) << endl; } return 0; }