結果

問題 No.2710 How many more?
ユーザー GOTKAKOGOTKAKO
提出日時 2024-03-31 15:27:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 210,968 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 15:27:52
合計ジャッジ時間 6,517 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 222 ms
6,676 KB
testcase_03 AC 131 ms
6,676 KB
testcase_04 AC 97 ms
6,676 KB
testcase_05 AC 75 ms
6,676 KB
testcase_06 AC 84 ms
6,676 KB
testcase_07 AC 97 ms
6,676 KB
testcase_08 AC 73 ms
6,676 KB
testcase_09 AC 186 ms
6,676 KB
testcase_10 AC 106 ms
6,676 KB
testcase_11 AC 176 ms
6,676 KB
testcase_12 AC 245 ms
6,676 KB
testcase_13 AC 259 ms
6,676 KB
testcase_14 AC 266 ms
6,676 KB
testcase_15 AC 262 ms
6,676 KB
testcase_16 AC 263 ms
6,676 KB
testcase_17 AC 261 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N,Q; cin >> N >> Q;
    vector<pair<int,int>> A(N);
    for(int i=0; i<N; i++){
        int a; cin >> a;
        A.at(i) = {a,i};
    }
    sort(A.begin(),A.end());
    vector<int> rev(N);
    for(int i=0; i<N; i++) rev.at(A.at(i).second) = i;

    while(Q--){
        int x,y; cin >> x >> y;
        x--; y--;
        auto [a1,ig] = A.at(rev.at(x));
        auto [a2,ign] = A.at(rev.at(y));

        if(a1 <= a2){cout << 0 << endl; continue;}
        int pos1 = upper_bound(A.begin(),A.end(),make_pair(a2,N+1))-A.begin();
        int pos2 = lower_bound(A.begin(),A.end(),make_pair(a1,-1))-A.begin();
        cout << pos2-pos1 << endl;
    }
}
0