結果

問題 No.230 Splarraay スプラレェーイ
ユーザー OrisanoOrisano
提出日時 2016-11-19 03:31:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 198 ms / 5,000 ms
コード長 2,814 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 155,316 KB
実行使用メモリ 7,572 KB
最終ジャッジ日時 2023-08-17 14:03:02
合計ジャッジ時間 4,317 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 88 ms
5,260 KB
testcase_10 AC 85 ms
4,380 KB
testcase_11 AC 51 ms
4,376 KB
testcase_12 AC 88 ms
5,292 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 79 ms
7,260 KB
testcase_15 AC 130 ms
6,940 KB
testcase_16 AC 155 ms
7,376 KB
testcase_17 AC 198 ms
7,572 KB
testcase_18 AC 117 ms
7,324 KB
testcase_19 AC 116 ms
7,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <vector>
namespace copr {
namespace seg_util {
constexpr int nextpow2(int x, int r = 1) {
  return r < x ? nextpow2(x, r + r) : r;
}
} // namespace seg_util
template <typename Monoid, typename Lazy>
struct LazySegTree {
  using data_type = typename Monoid::value_type;
  using lazy_type = typename Lazy::value_type;
  const int N;
  const data_type empty = Monoid::empty();
  const lazy_type nil = Lazy::empty();
  std::vector<data_type> data;
  std::vector<lazy_type> lazy;

  LazySegTree(int size) : N(seg_util::nextpow2(size)) {
    data.assign(N * 2, empty);
    lazy.assign(N * 2, nil);
  }
  inline void propagate(int x, int l, int r) {
    if (lazy[x] == nil) return;
    data[x] = Lazy::eval(data[x], lazy[x], l, r);
    if (x < N - 1) {
      lazy[x + x + 1] = Lazy::append(lazy[x + x + 1], lazy[x]);
      lazy[x + x + 2] = Lazy::append(lazy[x + x + 2], lazy[x]);
    }
    lazy[x] = nil;
  }
  void query(lazy_type v, int a, int b) { query(v, a, b, 0, 0, N); }
  void query(lazy_type v, int a, int b, int x, int l, int r) {
    propagate(x, l, r);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      lazy[x] = Lazy::append(lazy[x], v);
      propagate(x, l, r);
      return;
    }
    int m = (l + r) / 2;
    query(v, a, b, x + x + 1, l, m);
    query(v, a, b, x + x + 2, m, r);
    data[x] = Monoid::append(data[x + x + 1], data[x + x + 2]);
  }
  data_type concat(int a, int b) { return concat(a, b, 0, 0, N); }
  data_type concat(int a, int b, int x, int l, int r) {
    propagate(x, l, r);
    if (r <= a || b <= l) return empty;
    if (a <= l && r <= b) return data[x];
    int m = (l + r) / 2;
    return Monoid::append(concat(a, b, x + x + 1, l, m), concat(a, b, x + x + 2, m, r));
  }
};
} // namespace copr

using namespace std;

struct Sum {
  using value_type = int;
  static value_type append(value_type x, value_type y) { return x + y; }
  static value_type empty() { return 0; }
  struct FillQuery {
    using value_type = int;
    static value_type append(value_type x, value_type y) { return y; }
    static value_type empty() { return -1; }
    template <typename T>
    static T eval(T v, value_type x, int l, int r) {
      return (r - l) * x;
    }
  };
};

using ll = long long;

int main() {
  int N, Q;
  cin >> N >> Q;

  copr::LazySegTree<Sum, Sum::FillQuery> A{N}, B{N};
  ll a = 0, b = 0;
  for (int q = 0; q < Q; q++) {
    int x, l, r;
    cin >> x >> l >> r;
    r++;
    if (x == 0) {
      auto ac = A.concat(l, r);
      auto bc = B.concat(l, r);
      if (ac == bc) continue;
      if (ac < bc) {
        b += bc;
      } else {
        a += ac;
      }
    } else {
      A.query(x == 1, l, r);
      B.query(x == 2, l, r);
    }
  }
  a += A.concat(0, N);
  b += B.concat(0, N);
  cout << a << ' ' << b << endl;
}
0