結果

問題 No.2500 Products in a Range
ユーザー GOTKAKO
提出日時 2023-10-13 22:32:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 1,836 ms
コンパイル使用メモリ 176,908 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 18:17:27
合計ジャッジ時間 3,686 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 61
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:32:13: warning: 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: warning: 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