結果

問題 No.2710 How many more?
ユーザー ryota2357ryota2357
提出日時 2024-03-31 12:04:13
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 120,728 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 12:04:19
合計ジャッジ時間 5,320 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 221 ms
6,676 KB
testcase_03 AC 131 ms
6,676 KB
testcase_04 AC 97 ms
6,676 KB
testcase_05 AC 74 ms
6,676 KB
testcase_06 AC 84 ms
6,676 KB
testcase_07 AC 96 ms
6,676 KB
testcase_08 AC 71 ms
6,676 KB
testcase_09 AC 186 ms
6,676 KB
testcase_10 AC 107 ms
6,676 KB
testcase_11 AC 174 ms
6,676 KB
testcase_12 AC 247 ms
6,676 KB
testcase_13 AC 270 ms
6,676 KB
testcase_14 AC 264 ms
6,676 KB
testcase_15 AC 266 ms
6,676 KB
testcase_16 AC 262 ms
6,676 KB
testcase_17 AC 266 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0