結果

問題 No.230 Splarraay スプラレェーイ
ユーザー OrisanoOrisano
提出日時 2016-11-19 02:59:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 5,000 ms
コード長 2,689 bytes
コンパイル時間 2,084 ms
コンパイル使用メモリ 169,976 KB
実行使用メモリ 7,404 KB
最終ジャッジ日時 2023-08-17 13:59:55
合計ジャッジ時間 4,095 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 87 ms
5,132 KB
testcase_10 AC 87 ms
4,376 KB
testcase_11 AC 50 ms
4,376 KB
testcase_12 AC 88 ms
5,224 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 77 ms
7,384 KB
testcase_15 AC 136 ms
6,956 KB
testcase_16 AC 156 ms
6,980 KB
testcase_17 AC 184 ms
7,404 KB
testcase_18 AC 118 ms
7,296 KB
testcase_19 AC 111 ms
7,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int nextpow2(int x, int r = 1) {
  return r < x ? nextpow2(x, r + r) : r;
}

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();
  vector<data_type> data;
  vector<lazy_type> lazy;

  LazySegTree(int size) : N(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));
  }
};

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;

  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