結果

問題 No.2710 How many more?
ユーザー ku_senjanku_senjan
提出日時 2024-03-31 14:09:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 2,002 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 212,432 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:09:49
合計ジャッジ時間 5,885 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 187 ms
6,676 KB
testcase_03 AC 107 ms
6,676 KB
testcase_04 AC 79 ms
6,676 KB
testcase_05 AC 60 ms
6,676 KB
testcase_06 AC 68 ms
6,676 KB
testcase_07 AC 81 ms
6,676 KB
testcase_08 AC 60 ms
6,676 KB
testcase_09 AC 159 ms
6,676 KB
testcase_10 AC 88 ms
6,676 KB
testcase_11 AC 146 ms
6,676 KB
testcase_12 AC 208 ms
6,676 KB
testcase_13 AC 226 ms
6,676 KB
testcase_14 AC 224 ms
6,676 KB
testcase_15 AC 222 ms
6,676 KB
testcase_16 AC 251 ms
6,676 KB
testcase_17 AC 222 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
template<class T> using graph=vector<vector<T>>;
template<class T> using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
constexpr int INF32=INT_MAX/2;
constexpr ll INF64=1LL<<60;
constexpr array<int,4> DX4={0,1,0,-1};
constexpr array<int,4> DY4={-1,0,1,0};
constexpr array<int,8> DX8={0,1,1,1,0,-1,-1,-1};
constexpr array<int,8> DY8={-1,-1,0,1,1,1,0,-1};
inline int popcnt(ll n){return __builtin_popcountll(n);}
template<class T> inline bool chmax(T& a,const T& b){return a<b?a=b,true:false;}
template<class T> inline bool chmin(T& a,const T& b){return b<a?a=b,true:false;}
#define rep(i,s,n) for(ll i=(ll)(s);i<(ll)(n);i++)
#define rrep(i,s,n) for(ll i=(ll)(s);i>=(ll)(n);i--)
void _main();
int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(16);
	_main();
}

template<class T,class C=less<T>>
class Compress{
	private:
		vector<T> v;

	public:
		Compress(){}

		void push(const T x){
			v.push_back(x);
		}

		void build(){
			sort(v.begin(), v.end(), C());
			v.erase(unique(v.begin(),v.end()),v.end());
		}

		size_t size() const {
			return v.size();
		}

		T nth(const int i) const {
			assert(0<=i && i<int(v.size()));
			return v[i];
		}

		int get(const T x) const {
			int ng=-1, ok=int(v.size())-1;
			while(1<ok-ng){
				int mid=(ok+ng)/2;
				if(!C()(v[mid],x)) ok=mid;
				else ng=mid;
			}
			return ok;
		}

		bool count(const T x) const {
			return nth(get(x))==x;
		}
};

#include <atcoder/fenwicktree>
using atcoder::fenwick_tree;

void _main(){
	int N, Q; cin >> N >> Q;
	vector<ll> A(N); rep(i,0,N) cin >> A[i];

	Compress<ll> comp;
	rep(i,0,N) comp.push(A[i]);
	comp.build();

	fenwick_tree<ll> fw(comp.size());
	rep(i,0,N) fw.add(comp.get(A[i]), 1);

	while(Q--){
		int x, y; cin >> x >> y; x--; y--;

		int l = comp.get(A[y])+1, r = comp.get(A[x]);
		if(r<l){
			cout << 0 << endl;
			continue;
		}
		cout << fw.sum(l, r) << endl;
	}
}
0