結果

問題 No.2710 How many more?
ユーザー elphe
提出日時 2024-07-03 18:45:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 82,200 KB
最終ジャッジ日時 2025-02-22 01:54:03
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, Q, x, y, i;
    cin >> N >> Q;
    vector<pair<int, int>> runners(N);
    vector<int> rank_of(N);
    for (i = 0; i != N; ++i)
        cin >> runners[i].first, runners[i].second = i;
    sort(runners.begin(), runners.end());

    for (i = 0; i != N; ++i)
        rank_of[runners[i].second] = i;

    for (i = 0; i != Q; ++i)
    {
        cin >> x >> y;
        if (runners[rank_of[x - 1]].first <= runners[rank_of[y - 1]].first) cout << "0\n";
        else cout << lower_bound(runners.begin(), runners.end(), runners[rank_of[x - 1]]) - upper_bound(runners.begin(), runners.end(), runners[rank_of[y - 1]]) << '\n';
    }

    return 0;
}
0