結果

問題 No.230 Splarraay スプラレェーイ
ユーザー motimoti
提出日時 2015-07-07 05:42:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,069 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 75,700 KB
実行使用メモリ 68,924 KB
最終ジャッジ日時 2023-09-22 09:16:27
合計ジャッジ時間 3,957 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
68,344 KB
testcase_01 AC 26 ms
68,300 KB
testcase_02 AC 26 ms
68,348 KB
testcase_03 WA -
testcase_04 AC 26 ms
68,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 105 ms
68,280 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 143 ms
68,368 KB
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

enum class color { mine, yours, invalid };

template<int Max>
struct lazy_segtree {
  vector<int> val;  // 確定値
  vector<color> lazy; // 遅延値(自分の色かどうか: Mine, Yours or 塗りつぶしが一様でない: Invalid)

  lazy_segtree() { val.resize(Max*2); lazy.resize(Max*2); }

  int get(int x, int y, int l=0, int r=Max, int k=1) {
    if(r <= x || y <= l) { return 0; }
    if(x <= l && r <= y) { return val[k]; }
    x = max(x, l); y = min(y, r);
    if(lazy[k] != color::invalid) { return lazy[k] == color::mine ? (y-x) : 0; }
    return get(x, y, l, (l+r)/2, k*2) + get(x, y, (l+r)/2, r, k*2+1);
  }

  void update(int x, int y, color v, int l=0, int r=Max, int k=1) {
    if(l >= r) { return; }
    if(x <= l && r <= y) {                      // 現在調べている区間を完全に含む
      lazy[k] = v;                              // 指定された色で該当区間の節点kを塗りつぶす
      val[k] = v == color::mine ? (r-l) : 0;    // 得られる点数
    }
    else if(l < y && x < r) {                   // 交差
      if(lazy[k] != color::invalid) {           // 遅延値が残っている
        lazy[k*2] = lazy[k*2+1] = lazy[k];      // 遅延値の伝播
        val[k*2] = val[k*2+1] = lazy[k] == color::mine ? (r-l) / 2 : 0;
        lazy[k] = color::invalid;
      }

      update(x, y, v, l, (l+r)/2, k*2);
      update(x, y, v, (l+r)/2, r, k*2+1);
      val[k] = val[k*2] + val[k*2+1];
    }
  }
};

int N, Q;
ll AA, BB;
lazy_segtree<1<<21>  st[2];

int main() {

  cin >> N >> Q;
  while(Q--) {
    int x, l, r;
    cin >> x >> l >> r;
    if(x == 0) {
      int a = st[0].get(l, r+1);
      int b = st[1].get(l, r+1);
      if(a > b) { AA += a; }
      if(a < b) { BB += b; }
    }
    else {
      st[x-1].update(l, r+1, color::mine);
      st[(x-1)^1].update(l, r+1, color::yours);
    }
  }

  AA += st[0].get(0, N);
  BB += st[1].get(0, N);
  cout << AA << " " << BB << endl;

  return 0;
}
0