#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; const ll INF=9e18; int main() { ll N,Q; cin>>N>>Q; vector A (N); maphito; for (ll a = 0; a < N; a++){ cin>>A[a]; hito[a]=A[a]; } sort(A.begin(),A.end()); for (ll a = 0; a < Q; a++){ ll x,y; cin>>x>>y; x--;y--; ll x_doko=lower_bound(A.begin(),A.end(),hito[x])-A.begin(); ll y_doko=upper_bound(A.begin(),A.end(),hito[y])-A.begin()-1; //cout<<"x,y"<