結果

問題 No.230 Splarraay スプラレェーイ
ユーザー motimoti
提出日時 2015-07-13 00:18:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 148 ms / 5,000 ms
コード長 1,817 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 76,488 KB
実行使用メモリ 35,808 KB
最終ジャッジ日時 2023-09-22 14:36:52
合計ジャッジ時間 3,117 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
35,796 KB
testcase_01 AC 15 ms
35,628 KB
testcase_02 AC 16 ms
35,588 KB
testcase_03 AC 15 ms
35,588 KB
testcase_04 AC 15 ms
35,696 KB
testcase_05 AC 16 ms
35,780 KB
testcase_06 AC 24 ms
35,712 KB
testcase_07 AC 17 ms
35,768 KB
testcase_08 AC 18 ms
35,672 KB
testcase_09 AC 81 ms
35,792 KB
testcase_10 AC 116 ms
35,764 KB
testcase_11 AC 59 ms
35,484 KB
testcase_12 AC 79 ms
35,788 KB
testcase_13 AC 27 ms
35,808 KB
testcase_14 AC 91 ms
35,712 KB
testcase_15 AC 148 ms
35,676 KB
testcase_16 AC 148 ms
35,480 KB
testcase_17 AC 148 ms
35,660 KB
testcase_18 AC 132 ms
35,668 KB
testcase_19 AC 107 ms
35,660 KB
権限があれば一括ダウンロードができます

ソースコード

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, color::invalid); }

  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 col, int l=0, int r=Max, int k=1) {
    if(l >= r) { return ; }
    if(x <= l && r <= y) {
      lazy[k] = col;
      val[k] = lazy[k] != color::yours ? (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::yours ? (r-l) / 2 : 0;
        lazy[k] = color::invalid;
      }
      update(x, y, col, l, (l+r)/2, k*2);
      update(x, y, col, (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<<20> 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