結果

問題 No.2458 Line Up Charged Balls
ユーザー 👑 NachiaNachia
提出日時 2023-08-25 04:32:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,903 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 83,356 KB
実行使用メモリ 19,848 KB
最終ジャッジ日時 2023-08-25 04:32:20
合計ジャッジ時間 5,872 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
17,312 KB
testcase_01 AC 10 ms
17,376 KB
testcase_02 AC 10 ms
17,344 KB
testcase_03 AC 10 ms
17,412 KB
testcase_04 AC 10 ms
17,284 KB
testcase_05 AC 108 ms
19,724 KB
testcase_06 AC 106 ms
19,724 KB
testcase_07 AC 10 ms
17,292 KB
testcase_08 AC 10 ms
17,288 KB
testcase_09 AC 169 ms
19,444 KB
testcase_10 AC 49 ms
18,068 KB
testcase_11 AC 11 ms
17,412 KB
testcase_12 AC 11 ms
17,284 KB
testcase_13 AC 92 ms
18,732 KB
testcase_14 AC 97 ms
18,400 KB
testcase_15 AC 45 ms
18,468 KB
testcase_16 AC 82 ms
19,724 KB
testcase_17 AC 82 ms
19,656 KB
testcase_18 AC 82 ms
19,784 KB
testcase_19 AC 115 ms
19,784 KB
testcase_20 AC 103 ms
19,652 KB
testcase_21 AC 116 ms
19,700 KB
testcase_22 AC 106 ms
19,848 KB
testcase_23 AC 175 ms
19,652 KB
testcase_24 AC 117 ms
19,668 KB
testcase_25 AC 196 ms
19,796 KB
testcase_26 AC 170 ms
19,652 KB
testcase_27 AC 188 ms
19,652 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<i64> A, B;
    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);
        B.assign(N*2, -INF);
        off = L;
    }
    i64 maxval(i64 x){
        i64 pos = N + x - off;
        i64 ans = -INF;
        while(pos >= 1){
            ans = max(ans, A[pos] * x + B[pos]);
            pos /= 2;
        }
        return ans;
    }
    void update(i64 a, i64 b){
        i64 i = 1;
        while(true){
            if(A[i] * mid[i] + B[i] < a * mid[i] + b){
                swap(A[i], a);
                swap(B[i], b);
            }
            if(i >= N) break;
            bool rightup = a - A[i] > 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