結果

問題 No.631 Noelちゃんと電車旅行
ユーザー a_kawashiroa_kawashiro
提出日時 2018-01-06 09:43:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 2,268 bytes
コンパイル時間 1,217 ms
コンパイル使用メモリ 117,100 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-10 07:48:35
合計ジャッジ時間 4,797 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
6,816 KB
testcase_01 AC 144 ms
7,424 KB
testcase_02 AC 143 ms
7,552 KB
testcase_03 AC 143 ms
7,424 KB
testcase_04 AC 144 ms
7,424 KB
testcase_05 AC 145 ms
7,424 KB
testcase_06 AC 53 ms
6,940 KB
testcase_07 AC 35 ms
6,940 KB
testcase_08 AC 106 ms
7,424 KB
testcase_09 AC 114 ms
6,944 KB
testcase_10 AC 87 ms
7,552 KB
testcase_11 AC 77 ms
6,940 KB
testcase_12 AC 99 ms
7,424 KB
testcase_13 AC 80 ms
6,940 KB
testcase_14 AC 34 ms
6,940 KB
testcase_15 AC 69 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

class RangeAddRangeMax {
    public:
        int N;
        vector<LL> dat, sum_dat;
        RangeAddRangeMax(int n) {
            N = 1;
            while(N < n) N <<= 1;
            dat.assign(2*N-1, 0);
            sum_dat.assign(2*N-1, 0);
        }

        void add(int a, int b, LL x) { add(a,b,x,0,0,N); }
        LL add(int a, int b, LL x, int k, int l, int r) {
            if(b <= l or r <= a) return dat[k];
            if(a <= l and r <= b) {
                sum_dat[k] += x;
                return dat[k] += x;
            }
            const int m = (l+r)/2;
            return dat[k] = max(add(a,b,x,2*k+1,l,m),add(a,b,x,2*k+2,m,r))+sum_dat[k];
        }

        LL rangeMax(int a, int b) { return rangeMax(a,b,0,0,N); }
        LL rangeMax(int a, int b, int k, int l, int r) {
            if(b <= l or r <= a) return 0;
            if(a <= l and r <= b) return dat[k];
            const int m = (l+r)/2;
            return max(rangeMax(a,b,2*k+1,l,m),rangeMax(a,b,2*k+2,m,r))+sum_dat[k];
        }
};

int main(void){
    int N;GI(N);
    RangeAddRangeMax sg(N);
    REP(i,N-1){
        int t;GI(t);sg.add(i,i+1,t-3*i);
    }
    int M;GI(M);
    REP(i,M){
        int l,r;LL d;GI(l);GI(r);GLL(d);
        sg.add(l-1,r,d);
        printf("%lld\n",sg.rangeMax(0,N-1)+(N-1)*3);
    }
    return 0;
}
0