結果

問題 No.631 Noelちゃんと電車旅行
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-31 14:16:55
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 2,998 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 106,516 KB
実行使用メモリ 12,920 KB
最終ジャッジ日時 2023-09-03 23:36:44
合計ジャッジ時間 6,259 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
12,656 KB
testcase_01 AC 234 ms
12,920 KB
testcase_02 AC 234 ms
11,596 KB
testcase_03 AC 232 ms
11,920 KB
testcase_04 AC 233 ms
12,548 KB
testcase_05 AC 233 ms
12,600 KB
testcase_06 AC 94 ms
7,796 KB
testcase_07 AC 47 ms
7,128 KB
testcase_08 AC 174 ms
11,496 KB
testcase_09 AC 209 ms
8,188 KB
testcase_10 AC 144 ms
12,472 KB
testcase_11 AC 126 ms
7,956 KB
testcase_12 AC 157 ms
12,872 KB
testcase_13 AC 156 ms
6,592 KB
testcase_14 AC 69 ms
4,384 KB
testcase_15 AC 131 ms
6,556 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum INF = 10L^^18;

class SegmentTree {
  int n;
  long[] mx, add;
  this(long[] ini) {
    const n_ = cast(int)(ini.length);
    for (n = 1; n < n_; n <<= 1) {}
    mx = new long[n << 1];
    add = new long[n << 1];
    mx[] = -INF;
    add[] = 0;
    foreach (i; 0 .. n_) {
      mx[n + i] = ini[i];
    }
    foreach_reverse (a; 1 .. n) {
      mx[a] = max(mx[a << 1], mx[a << 1 | 1]);
    }
  }
  // [a, b)
  private long query(int u, int x, int y, int a, int b, long val) {
    chmax(a, x);
    chmin(b, y);
    if (a >= b) {
      return -INF;
    }
    if (a == x && b == y) {
      mx[u] += val;
      add[u] += val;
      return mx[u];
    }
    assert(u < n);
    const uL = u << 1 | 0;
    const uR = u << 1 | 1;
    const mid = (x + y) >> 1;
    if (add[u] != 0) {
      mx[uL] += add[u];
      mx[uR] += add[u];
      add[uL] += add[u];
      add[uR] += add[u];
      add[u] = 0;
    }
    const resL = query(uL, x, mid, a, b, val);
    const resR = query(uR, mid, y, a, b, val);
    mx[u] = max(mx[uL], mx[uR]);
    return max(resL, resR);
  }
  // [a, b]
  long query(int a, int b, long val) {
    return query(1, 0, n, a, b + 1, val);
  }
}


int N;
long[] T;
int M;
int[] L, R;
long[] D;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      T = new long[N - 1];
      foreach (i; 0 .. N - 1) {
        T[i] = readLong();
      }
      M = readInt();
      L = new int[M];
      R = new int[M];
      D = new long[M];
      foreach (m; 0 .. M) {
        L[m] = readInt() - 1;
        R[m] = readInt() - 1;
        D[m] = readInt();
      }
      
      auto ini = new long[N];
      foreach (i; 0 .. N - 1) {
        ini[i] = T[i] + 3 * (N - 1 - i);
      }
      auto seg = new SegmentTree(ini);
      foreach (m; 0 .. M) {
        seg.query(L[m], R[m], D[m]);
        writeln(seg.mx[1]);
      }
    }
  } catch (EOFException e) {
  }
}
0