結果

問題 No.2710 How many more?
ユーザー GOTKAKO
提出日時 2024-03-31 15:27:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 203,720 KB
最終ジャッジ日時 2025-02-20 17:54:53
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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