#include using namespace std; #define rep(i,n) for(int i = 0;i < n;i++) template bool chmin(T &a,T b){ if(a>b){a = b;return true;} return false; } template bool chmax(T &a,T b){ if(a> N >> Q; vectorA(N); rep(i,N)cin >> A[i];//ゴールまでのキョリ vectorvec = A; sort(all(vec)); rep(qi,Q){ int x,y;cin >> x >> y; x--;y--; //xがyに追いつくためには何人ぬかす必要があるか? //等号は含めない // xよりも値が小さい、yよりも大きいのは何人いるか? auto itx = lower_bound(all(vec),A[x]);itx--; auto ity = upper_bound(all(vec),A[y]); cout << max(0,int(itx-ity+1)) << endl; } }