結果

問題 No.631 Noelちゃんと電車旅行
ユーザー tottoripapertottoripaper
提出日時 2018-01-06 00:27:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,546 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 165,236 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 07:48:02
合計ジャッジ時間 7,135 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 249 ms
6,816 KB
testcase_01 AC 287 ms
6,944 KB
testcase_02 AC 289 ms
6,940 KB
testcase_03 AC 290 ms
6,940 KB
testcase_04 AC 286 ms
6,940 KB
testcase_05 AC 288 ms
6,940 KB
testcase_06 AC 121 ms
6,940 KB
testcase_07 AC 54 ms
6,940 KB
testcase_08 AC 211 ms
6,944 KB
testcase_09 AC 268 ms
6,944 KB
testcase_10 AC 172 ms
6,944 KB
testcase_11 AC 160 ms
6,940 KB
testcase_12 AC 191 ms
6,944 KB
testcase_13 AC 208 ms
6,940 KB
testcase_14 AC 101 ms
6,940 KB
testcase_15 AC 171 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

constexpr int BUCKET_SIZE = 320;

ll T[100100], TB[100100 / BUCKET_SIZE + 10], SB[100100 / BUCKET_SIZE + 10];

// [l, r)
void update(int l, int r, ll d){
    while(l < r && l % BUCKET_SIZE > 0){
        T[l] += d;
        TB[l / BUCKET_SIZE] = max(TB[l / BUCKET_SIZE], T[l] + SB[l / BUCKET_SIZE]);
        ++l;
    }

    while(l < r && r % BUCKET_SIZE > 0){
        --r;
        T[r] += d;
        TB[r / BUCKET_SIZE] = max(TB[r / BUCKET_SIZE], T[r] + SB[r / BUCKET_SIZE]);
    }

    l /= BUCKET_SIZE;
    r /= BUCKET_SIZE;
    while(l < r){
        SB[l] += d;
        TB[l] += d;
        ++l;
    }
}

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

    int N;
    std::cin >> N;

    for(int i=1;i<N;++i){
        std::cin >> T[i];
    }

    {
        int x = 3;
        for(int i=N-1;i>=1;--i){
            T[i] += x;
            TB[i / BUCKET_SIZE] = max(TB[i / BUCKET_SIZE], T[i]);
            x += 3;
        }
    }

    int M;
    std::cin >> M;

    for(int i=0;i<M;++i){
        ll l, r, d;
        std::cin >> l >> r >> d;

        update(l, r + 1, d);

        ll res = *max_element(TB, TB + 100100 / BUCKET_SIZE + 3);
        std::cout << res << std::endl;
    }
}
0