結果
| 問題 |
No.2710 How many more?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-31 12:04:13 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 243 ms / 2,000 ms |
| コード長 | 879 bytes |
| コンパイル時間 | 1,121 ms |
| コンパイル使用メモリ | 130,904 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-09-30 17:54:43 |
| 合計ジャッジ時間 | 4,882 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 |
ソースコード
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, q;
cin >> n; cin >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) { cin >> a[i]; }
assert(2 <= n && n <= 100000);
assert(1 <= q && q <= 100000);
for (int i = 0; i < n; ++i) { assert(1 <= a[i] && a[i] <= 1000000000); }
vector<int> b(a);
sort(b.begin(), b.end());
while (q--) {
int x, y;
cin >> x >> y;
int dist_x = a[x - 1];
int dist_y = a[y - 1];
if (dist_x <= dist_y) {
cout << 0 << endl;
} else {
int num_x = lower_bound(b.begin(), b.end(), dist_x) - b.begin();
int num_y = upper_bound(b.begin(), b.end(), dist_y) - b.begin();
int ans = num_x - num_y;
cout << ans << endl;
}
}
return 0;
}