結果

問題 No.2710 How many more?
ユーザー blue_jamblue_jam
提出日時 2024-03-31 14:14:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 722 bytes
コンパイル時間 4,612 ms
コンパイル使用メモリ 267,496 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:14:50
合計ジャッジ時間 9,068 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 249 ms
6,676 KB
testcase_03 AC 146 ms
6,676 KB
testcase_04 AC 105 ms
6,676 KB
testcase_05 AC 83 ms
6,676 KB
testcase_06 AC 93 ms
6,676 KB
testcase_07 AC 103 ms
6,676 KB
testcase_08 AC 76 ms
6,676 KB
testcase_09 AC 207 ms
6,676 KB
testcase_10 AC 120 ms
6,676 KB
testcase_11 AC 196 ms
6,676 KB
testcase_12 AC 272 ms
6,676 KB
testcase_13 AC 325 ms
6,676 KB
testcase_14 AC 292 ms
6,676 KB
testcase_15 AC 295 ms
6,676 KB
testcase_16 AC 300 ms
6,676 KB
testcase_17 AC 321 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
using namespace atcoder;

using ll = long long;


int main() {
    ll N, Q;
    cin >> N >> Q;
    vector<ll> A(N);
    vector<pair<ll, ll>> B(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        A[i] = -A[i];
        B[i] = {A[i], i};
    }
    sort(B.begin(), B.end());

    for (ll q = 0; q < Q; q++) {
        ll x, y;
        cin >> x >> y;

        x--; y--;
        ll p1 = A[x];
        ll p2 = A[y];

        ll xi = lower_bound(B.begin(), B.end(), make_pair(p1, N)) - B.begin();
        ll yi = lower_bound(B.begin(), B.end(), make_pair(p2 - 1, N)) - B.begin();

        cout << max(yi - xi, 0LL) << endl;
    }

    return 0;
}
0