結果
| 問題 |
No.2710 How many more?
|
| コンテスト | |
| ユーザー |
shkiiii_
|
| 提出日時 | 2024-03-31 17:37:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 2,000 ms |
| コード長 | 2,256 bytes |
| コンパイル時間 | 2,402 ms |
| コンパイル使用メモリ | 202,184 KB |
| 最終ジャッジ日時 | 2025-02-20 18:09:30 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 |
ソースコード
#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;
}
shkiiii_