結果

問題 No.631 Noelちゃんと電車旅行
ユーザー ikdikd
提出日時 2018-01-07 02:43:25
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 296 ms / 2,000 ms
コード長 1,647 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 12,616 KB
最終ジャッジ日時 2023-09-03 17:54:14
合計ジャッジ時間 6,317 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 204 ms
11,304 KB
testcase_01 AC 291 ms
12,216 KB
testcase_02 AC 296 ms
12,008 KB
testcase_03 AC 294 ms
12,348 KB
testcase_04 AC 293 ms
12,364 KB
testcase_05 AC 292 ms
12,616 KB
testcase_06 AC 112 ms
7,100 KB
testcase_07 AC 56 ms
7,720 KB
testcase_08 AC 209 ms
12,104 KB
testcase_09 AC 250 ms
7,668 KB
testcase_10 AC 170 ms
11,360 KB
testcase_11 AC 155 ms
7,844 KB
testcase_12 AC 194 ms
12,164 KB
testcase_13 AC 184 ms
6,484 KB
testcase_14 AC 80 ms
4,384 KB
testcase_15 AC 154 ms
6,476 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.exception;

  int n; rd(n);
  auto t=readln.split.to!(long[]);
  enforce(t.length==n-1);

  auto st=new LSegT(t);
  int q; rd(q);
  while(q--){
    int l, r; long d; rd(l, r, d);
    st.radd(l-1, r, d);
    writeln(st.rmax(0, n-1));
  }
}

class LSegT{
  static int sz=1;
  long[] seg, laz;
  import std.algorithm;
  this(long[] a){
    import std.conv;
    auto n=to!int(a.length);
    while(sz<n) sz*=2;
    seg.length=laz.length=(sz*2-1);
    foreach(i; 0..n) seg[i+sz-1]=a[i]+(n-i)*3;
    for(auto i=sz-2; i>=0; i--)
      seg[i]=max(seg[i*2+1], seg[i*2+2]);
  }

  void fix(int i, long x){
    laz[i]+=x;
    seg[i]+=x;
  }

  void push(int i){
    if(laz[i]>0){
      fix(i*2+1, laz[i]);
      fix(i*2+2, laz[i]);
      laz[i]=0;
    }
  }

  void radd(int l, int r, long x, int i=0, int il=0, int ir=sz){
    if(ir<=l || r<=il) return;
    if(l<=il && ir<=r){fix(i, x); return;}
    push(i);
    auto m=(il+ir)/2;
    radd(l, r, x, i*2+1, il, m);
    radd(l, r, x, i*2+2, m, ir);
    seg[i]=max(seg[i*2+1], seg[i*2+2]);
  }

  long rmax(int l, int r, int i=0, int il=0, int ir=sz){
    if(ir<=l || r<=il) return -1;
    if(l<=il && ir<=r) return seg[i];
    push(i);
    auto m=(il+ir)/2,
         vl=rmax(l, r, i*2+1, il, m),
         vr=rmax(l, r, i*2+2, m, ir);
    return max(vl, vr);
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}
0