結果

問題 No.2458 Line Up Charged Balls
ユーザー 👑 NachiaNachia
提出日時 2023-09-02 01:03:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,942 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 85,088 KB
実行使用メモリ 19,764 KB
最終ジャッジ日時 2023-09-02 01:03:40
合計ジャッジ時間 5,313 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
17,312 KB
testcase_01 AC 8 ms
17,304 KB
testcase_02 AC 9 ms
17,464 KB
testcase_03 AC 9 ms
17,248 KB
testcase_04 AC 8 ms
17,304 KB
testcase_05 AC 94 ms
19,748 KB
testcase_06 AC 91 ms
19,676 KB
testcase_07 AC 8 ms
17,320 KB
testcase_08 AC 9 ms
17,424 KB
testcase_09 AC 146 ms
19,500 KB
testcase_10 AC 46 ms
18,096 KB
testcase_11 AC 10 ms
17,216 KB
testcase_12 AC 9 ms
17,652 KB
testcase_13 AC 86 ms
18,576 KB
testcase_14 AC 92 ms
18,540 KB
testcase_15 AC 41 ms
18,276 KB
testcase_16 AC 74 ms
19,764 KB
testcase_17 AC 75 ms
19,676 KB
testcase_18 AC 77 ms
19,696 KB
testcase_19 AC 113 ms
19,684 KB
testcase_20 AC 97 ms
19,624 KB
testcase_21 AC 101 ms
19,676 KB
testcase_22 AC 95 ms
19,636 KB
testcase_23 AC 161 ms
19,636 KB
testcase_24 AC 108 ms
19,636 KB
testcase_25 AC 172 ms
19,680 KB
testcase_26 AC 150 ms
19,624 KB
testcase_27 AC 173 ms
19,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;

struct LiCiaoTree {
    int N = 0;
    i64 off = 0;
    vector<i64> P;
    vector<i64> mid;
    vector<pair<i64, i64>> A;
    LiCiaoTree(int L, int R){
        N = 1; while(N < R-L+1) N *= 2;
        P.resize(N, R);
        mid.resize(N*2);
        rep(i,R-L+1) P[i] = L+i;
        for(int d=0; (1<<d)<N; d++){
            int q = N >> d;
            rep(i,1<<d) mid[(1<<d)+i] = P[q*i + q/2];
        }
        rep(i,N) mid[N+i] = P[i];
        A.assign(N*2, {0,-INF});
        off = L;
    }
    i64 maxval(i64 x){
        i64 pos = N + x - off;
        i64 ans = -INF;
        while(pos >= 1){
            ans = max(ans, A[pos].first * x + A[pos].second);
            pos /= 2;
        }
        return ans;
    }
    void update(i64 a, i64 b){
        i64 i = 1;
        pair<i64, i64> f = {a,b};
        while(true){
            if(A[i].first * mid[i] + A[i].second < f.first * mid[i] + f.second){
                swap(A[i], f);
            }
            if(i >= N) break;
            bool rightup = f.first - A[i].first > 0;
            i = i * 2 + (rightup ? 1 : 0);
        }
    }
};

int main(){
    int N; cin >> N;
    vector<i64> Q(N); rep(i,N) cin >> Q[i];
    auto ds = LiCiaoTree(-110000, 110000);
    i64 ans = -INF;
    rep(i,N){
        i64 prevmax = ds.maxval(Q[i]);
        ans = max(ans, prevmax);
        if(prevmax < 0) prevmax = 0;
        ds.update(Q[i], prevmax);
    }
    cout << ans << endl;
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0