結果

問題 No.2710 How many more?
ユーザー blue_jamblue_jam
提出日時 2024-03-31 14:14:40
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 286 ms / 2,000 ms
コード長 722 bytes
コンパイル時間 4,386 ms
コンパイル使用メモリ 267,704 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-30 19:13:48
合計ジャッジ時間 8,588 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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