結果

問題 No.230 Splarraay スプラレェーイ
ユーザー motimoti
提出日時 2015-07-12 23:18:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,802 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 75,752 KB
実行使用メモリ 68,896 KB
最終ジャッジ日時 2023-09-22 14:35:59
合計ジャッジ時間 3,277 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
68,848 KB
testcase_01 AC 26 ms
68,344 KB
testcase_02 AC 24 ms
68,692 KB
testcase_03 WA -
testcase_04 AC 26 ms
68,212 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 104 ms
68,204 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 144 ms
68,260 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 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<<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