結果

問題 No.2710 How many more?
ユーザー BBhorseBBhorse
提出日時 2024-03-31 15:04:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 628 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 174,140 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-30 20:13:52
合計ジャッジ時間 5,189 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll=long long;
#define rep(i,s,n) for (ll i = (s); i < (n); i++)
using namespace std;
using Graph = vector<vector<ll>>;
ll MOD=998244353;
const ll INF=1e18;


int main(){
  ll N,Q;
  cin>>N>>Q;
  vector<ll> A(N);
  vector<ll> Z(N);
  rep(i,0,N){
    cin>>A[i];
    Z[i]=A[i];
  }
  sort(A.begin(),A.end());
  rep(i,0,Q){
    ll x,y;
    cin>>x>>y;
    x--;y--;
    auto itrX=lower_bound(A.begin(),A.end(),Z[x]);
    ll idxX=distance(A.begin(),itrX);
    auto itrY=upper_bound(A.begin(),A.end(),Z[y]);
    itrY--;
    ll idxY=distance(A.begin(),itrY);

    cout<<max((ll)0,idxX-idxY-1)<<endl;

  }
}
0