結果

問題 No.2710 How many more?
ユーザー rinrionrinrion
提出日時 2024-03-31 15:14:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,276 bytes
コンパイル時間 4,224 ms
コンパイル使用メモリ 239,228 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2024-03-31 15:15:09
合計ジャッジ時間 18,305 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 752 ms
7,424 KB
testcase_03 AC 661 ms
7,680 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 141 ms
6,548 KB
testcase_08 AC 246 ms
6,548 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 448 ms
6,548 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;
using ll = long long;

#define rep(i, s, n) for(int i = s; i < (int)(n); i++)
#define repr(i, s, n) for(int i = ((int)(n) - 1); i >= s; i--)
#define sz(x) ((int)(x).size())
#define inf_int (int) (1e9 + 7)
#define inf_ll (ll) (1e+18)

int main(){
	int n, q;
	cin >> n >> q;
	
	vector<int> a(n);
	map<int, int> ct;
	rep(i, 0, n){
		cin >> a[i];
		ct[a[i]] ++;
	}

	vector<int> b = a; // コピー
	sort(b.begin(), b.end()); // b を小さい順にソート
	b.erase(unique(b.begin(), b.end()), b.end()); // b から重複を除去する
	
	vector<int> res(a.size()); 
	for (int i = 0; i < a.size(); ++i) res[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();

	vector<int> jb (n);
	rep(i, 0, n){
		jb[res[i]] = a[i];
	}
	vector<int> rct (n);
	rct[0] = ct[jb[0]];
	rep(i, 1, n){
		rct[i] = rct[i - 1] + ct[jb[i]];
	}
	
	cerr <<"res:\n";for(auto x: res) cerr << x <<" "; cerr << "\n" ;
	cerr <<"jb:\n";for(auto x: jb) cerr << x <<" "; cerr << "\n" ;
	cerr <<"rct:\n";for(auto x: rct) cerr << x <<" "; cerr << "\n" ;
	

	rep(i, 0, q){
		int x, y;
		cin >> x >> y;
		x--; 
		y--;

		if(res[x] <= res[y]) cout << 0 << endl;
		else  cout <<rct[res[x]] - rct[res[y]] - 1<< endl;
	}
	
}
0