結果

問題 No.2710 How many more?
ユーザー うえこうえこ
提出日時 2024-03-31 14:06:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 286 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 174,568 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:07:06
合計ジャッジ時間 5,846 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 220 ms
6,676 KB
testcase_03 AC 132 ms
6,676 KB
testcase_04 AC 105 ms
6,676 KB
testcase_05 AC 75 ms
6,676 KB
testcase_06 AC 89 ms
6,676 KB
testcase_07 AC 90 ms
6,676 KB
testcase_08 AC 68 ms
6,676 KB
testcase_09 AC 187 ms
6,676 KB
testcase_10 AC 105 ms
6,676 KB
testcase_11 AC 169 ms
6,676 KB
testcase_12 AC 243 ms
6,676 KB
testcase_13 AC 286 ms
6,676 KB
testcase_14 AC 260 ms
6,676 KB
testcase_15 AC 260 ms
6,676 KB
testcase_16 AC 266 ms
6,676 KB
testcase_17 AC 267 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll=long long;
const long long INF=1LL<<60;
void Compress(std::vector<ll>& A)
{
    std::vector<ll> B=A;//
    std::sort(B.begin(),B.end());
    B.erase(std::unique(B.begin(),B.end()),B.end());
    for(auto& a:A){
        a=static_cast<ll>(std::lower_bound(B.begin(),B.end(),a)-B.begin());
    }
}
int main(){
    ll n,q;
    std::cin >> n >> q;
    std::vector<ll>A(n);
    for(auto&a:A){
        std::cin >> a;
        a*=-1;
    }
    Compress(A);
    std::vector<ll>sum(n+1);
    for(int i=0;i<n;++i)sum[A[i]]++;
    for(int i=0;i<n;++i)sum[i+1]+=sum[i];
    while(q--){
        ll x,y;
        std::cin >> x >> y;
        --x;--y;
        x=A[x];y=A[y];
        if(y==0)std::cout << 0 << '\n';
        else std::cout << std::max(0LL,sum[y-1]-sum[x]) << '\n';
    }
}
0