#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); vector> narabikae (N); for (ll a = 0; a < N; a++){ cin>>A[a]; narabikae[a]={A[a],a}; } //順位を求める ll now=0; vector num (N); sort(narabikae.begin(),narabikae.end()); for (ll a = 0; a < N; a++){ ll hito=narabikae[a].second; num[hito]=now; now++; if(a!=0){ ll maeno_hito=narabikae[a-1].second; // 同じ場所にいるなら同じ順位 if(narabikae[a-1].first==narabikae[a].first){ num[hito]=num[maeno_hito]; } } } for (ll a = 0; a < Q; a++){ ll x,y; cin>>x>>y; x--;y--; ll x_num=num[x]; ll y_num=num[y]; ll sa = x_num-y_num; cout<