結果

問題 No.844 split game
ユーザー yakamotoyakamoto
提出日時 2019-06-28 22:30:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 2,788 bytes
コンパイル時間 1,742 ms
コンパイル使用メモリ 174,812 KB
実行使用メモリ 6,436 KB
最終ジャッジ日時 2023-09-14 22:17:59
合計ジャッジ時間 5,175 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
4,688 KB
testcase_01 AC 17 ms
5,420 KB
testcase_02 AC 44 ms
5,160 KB
testcase_03 AC 32 ms
6,008 KB
testcase_04 AC 17 ms
4,380 KB
testcase_05 AC 48 ms
6,156 KB
testcase_06 AC 15 ms
4,376 KB
testcase_07 AC 13 ms
5,480 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 37 ms
4,380 KB
testcase_10 AC 51 ms
5,112 KB
testcase_11 AC 49 ms
6,192 KB
testcase_12 AC 36 ms
4,380 KB
testcase_13 AC 22 ms
4,376 KB
testcase_14 AC 21 ms
4,576 KB
testcase_15 AC 52 ms
6,224 KB
testcase_16 AC 53 ms
6,280 KB
testcase_17 AC 53 ms
6,436 KB
testcase_18 AC 53 ms
6,288 KB
testcase_19 AC 52 ms
6,168 KB
testcase_20 AC 53 ms
6,220 KB
testcase_21 AC 53 ms
6,312 KB
testcase_22 AC 53 ms
6,272 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 5 ms
4,384 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 6 ms
4,376 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 7 ms
4,380 KB
testcase_36 AC 5 ms
4,376 KB
testcase_37 AC 9 ms
4,380 KB
testcase_38 AC 18 ms
4,380 KB
testcase_39 AC 37 ms
4,656 KB
testcase_40 AC 12 ms
4,388 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,384 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

namespace DECLARATIONS {
  using namespace std;

  using ll = long long;
  using PI = pair<int, int>;
  template<class T> using V = vector<T>;
  using VI = V<int>;
#define _1 first
#define _2 second

#ifdef MY_DEBUG
# define DEBUG(x) x
#else
# define DEBUG(x)
#endif

  template<class T>
  inline void debug(T &A) {
    DEBUG(
        for (const auto &a : A) {
          cerr << a << " ";
        }
        cerr << '\n';
    )
  }

  template<class T>
  inline void debug_dim2(T &A) {
    DEBUG(
        for (const auto &as : A) {
          debug(as);
        }
    )
  }

  template<typename ... Args>
  inline void debug(const char *format, Args const &... args) {
    DEBUG(
        fprintf(stderr, format, args ...);
        cerr << '\n';
    )
  }

  template<typename ... Args>
  string format(const std::string &fmt, Args ... args) {
    size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args ...);
    std::vector<char> buf(len + 1);
    std::snprintf(&buf[0], len + 1, fmt.c_str(), args ...);
    return std::string(&buf[0], &buf[0] + len);
  }
}
using namespace DECLARATIONS;

const int MOD = 1000000007;


template<class T>
class SegmentTree {
private:
  int calcN(int x) {
    int k = 1 << (31 - __builtin_clz(x));
    return k == x ? k : k << 1;
  }

public:
  int N;
  V<T> dat;
  const T zero = (ll)-1e18;

  inline T f(T a, T b) {
    return max(a, b);
  }

  SegmentTree(int n): N(calcN(n)), dat(2 * this->N) {
    if (zero != 0) std::fill(dat.begin(), dat.end(), zero);
  }

  void update(int i, T a) {
    int ix = i + N;
    dat[ix] = a;
    while(ix > 1) {
      int p = ix >> 1;
      dat[p] = f(dat[ix], dat[ix ^ 1]);
      ix = p;
    }
  }

  /**
   * [a, b)
   */
  T query(int a, int b) {
    T res = zero;
    int l = a + N, r = b - 1 + N;
    while(l <= r) {
      if ((l&1)) res = f(res, dat[l]);
      if (!(r&1)) res = f(res, dat[r]);
      l = (l + 1) >> 1; // 右の子供なら右の親に移動
      r = (r - 1) >> 1; // 左の子供なら左の親に移動
    }
    return res;
  }
};

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

  int N, M, A;
  cin >> N >> M >> A;
  V<pair<PI, int>> S(M);
  for (int i = 0; i < M; ++i) {
    int l, r, p;
    cin >> l >> r >> p;
    S[i] = {PI(r, l-1), p}; // rで降順
  }
  sort(S.begin(), S.end());

  SegmentTree<ll> t(N + 1);
  t.update(0, 0);
  for (int i = 0; i < M; ++i) {
    // (r, l)なのに注意
    int l = S[i]._1._2;
    int r = S[i]._1._1;
    int p = S[i]._2;
    ll v = max(t.query(l, l + 1) - A, t.query(0, l) - 2 * A) + p;
    debug("l:%d r:%d p:%d v:%d", l, r, p, v);
    if (r == N) v += A; // Nはただで線を引ける
    if (t.query(r, r + 1) < v) t.update(r, v);
  }

  ll ans = t.query(0, N + 1);
  cout << ans;

  return 0;
}
0