結果

問題 No.2500 Products in a Range
ユーザー GOTKAKOGOTKAKO
提出日時 2023-10-13 22:32:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 176,188 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 22:32:47
合計ジャッジ時間 4,268 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 8 ms
4,352 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 25 ms
4,348 KB
testcase_11 AC 32 ms
4,348 KB
testcase_12 AC 13 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 19 ms
4,352 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 4 ms
4,352 KB
testcase_23 AC 3 ms
4,356 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 46 ms
4,348 KB
testcase_26 AC 44 ms
4,348 KB
testcase_27 AC 44 ms
4,356 KB
testcase_28 AC 3 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 11 ms
4,348 KB
testcase_34 AC 26 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 2 ms
4,352 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 2 ms
4,352 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 6 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 46 ms
4,348 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 1 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 3 ms
4,348 KB
testcase_53 AC 2 ms
4,352 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,352 KB
testcase_56 AC 3 ms
4,348 KB
testcase_57 AC 3 ms
4,352 KB
testcase_58 AC 2 ms
4,356 KB
testcase_59 AC 3 ms
4,348 KB
testcase_60 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:32:13: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   32 |         auto[l,r] = range.at(i);
      |             ^
main.cpp:37:17: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   37 |             auto[l2,r2] = range.at(k);
      |                 ^

ソースコード

diff #

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


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

    long long N,L,R; cin >> N >> L >> R;
    vector<long long> A(N);
    for(auto &a : A) cin >> a;
    sort(A.begin(),A.end());

    vector<pair<int,int>> range(N);
    for(int i=0; i<N; i++){
        long long l = L,r = R,a = A.at(i),mina,maxa;
        if(a < 0){mina = r/abs(a)*(-1),maxa = (l-a-1)/abs(a)*(-1);}
        else if(a == 0){
            if(l <= 0 && 0 <= r){mina = -1e18; maxa = 1e18;}
            else{mina = 1e18; maxa = -1e18;}
        }
        else{mina = (l+a-1)/a; maxa = r/a;}

        int posl = lower_bound(A.begin()+i+1,A.end(),mina)-A.begin();
        int posr = upper_bound(A.begin()+i+1,A.end(),maxa)-A.begin();
        posr--;
        range.at(i) = {posl,posr};
    }

    vector<int> B(N,1);
    for(int i=0; i<N; i++){
        auto[l,r] = range.at(i);

        int now = 1;
        for(int k=l; k<=r; ){
            now++;
            auto[l2,r2] = range.at(k);
            k = max(k+1,l2); r = min(r2,r);
        }
        B.at(i) = now;
    }

    int answer = *max_element(B.begin(),B.end());
    cout << answer << endl;

}
0