結果

問題 No.2710 How many more?
ユーザー shkiiii_shkiiii_
提出日時 2024-03-31 17:37:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 2,256 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 210,852 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 17:37:31
合計ジャッジ時間 4,707 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 73 ms
6,676 KB
testcase_03 AC 50 ms
6,676 KB
testcase_04 AC 48 ms
6,676 KB
testcase_05 AC 31 ms
6,676 KB
testcase_06 AC 42 ms
6,676 KB
testcase_07 AC 24 ms
6,676 KB
testcase_08 AC 23 ms
6,676 KB
testcase_09 AC 69 ms
6,676 KB
testcase_10 AC 38 ms
6,676 KB
testcase_11 AC 52 ms
6,676 KB
testcase_12 AC 89 ms
6,676 KB
testcase_13 AC 97 ms
6,676 KB
testcase_14 AC 111 ms
6,676 KB
testcase_15 AC 99 ms
6,676 KB
testcase_16 AC 99 ms
6,676 KB
testcase_17 AC 99 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}


// 閉区間[]
template<typename T>
class BIT{
  public:
  //0-indexed
  vector<T> s;
  const int n;
  BIT (int n_):s(n_+1,0),n(n_){}
  T sum(int i){
    i++;
    T k = 0;
    while(i > 0){
      k += s[i];
      i -= i & (-i);
    }
    return k;
  }
  // [l,r]
  T sum(int l,int r){
    return sum(r)-sum(l-1);
  }
  void add(int pos,T val){
    pos++;
    while(pos <= n){
      s[pos] += val;
      pos += pos & (-pos);
    }
  }
  int lower_bound(T k){
    int len = 1;
    while(len < n)len <<= 1;
    int l = 0;
    T x = 0;
    for(;len > 0;len >>= 1){
      if(l+len <= n && s[l+len]+x < k)x += s[l+len],l += len;
    }
    return l;
  }
};

int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n,Q;
  cin >> n >> Q;
  vi a(n);cin >> a;
  vi cor;
  rep(i,n)cor.emplace_back(a[i]);
  sort(ALL(cor));
  cor.erase(unique(ALL(cor)),cor.end());
  BIT<int> bit(sz(cor));
  rep(i,n)bit.add(LB(cor,a[i]),1);
  rep(i,Q){
    int x,y;cin >> x >> y;
    x--;y--;
    int res = 0;
    int iy = LB(cor,a[y]),ix = LB(cor,a[x]);
    if(iy < ix-1){
      res = bit.sum(iy+1,ix-1);
    }
    cout << res << "\n";
  }


  return 0;
}
0