結果

問題 No.230 Splarraay スプラレェーイ
ユーザー motimoti
提出日時 2015-07-13 00:15:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 234 ms / 5,000 ms
コード長 1,721 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 265,136 KB
最終ジャッジ日時 2023-09-22 14:36:31
合計ジャッジ時間 4,933 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
265,072 KB
testcase_01 AC 101 ms
265,136 KB
testcase_02 AC 101 ms
265,068 KB
testcase_03 AC 103 ms
265,048 KB
testcase_04 AC 103 ms
265,124 KB
testcase_05 AC 103 ms
265,056 KB
testcase_06 AC 111 ms
265,068 KB
testcase_07 AC 103 ms
265,100 KB
testcase_08 AC 105 ms
265,112 KB
testcase_09 AC 169 ms
265,056 KB
testcase_10 AC 209 ms
265,128 KB
testcase_11 AC 145 ms
265,124 KB
testcase_12 AC 186 ms
265,088 KB
testcase_13 AC 107 ms
265,128 KB
testcase_14 AC 169 ms
264,856 KB
testcase_15 AC 232 ms
264,916 KB
testcase_16 AC 234 ms
265,068 KB
testcase_17 AC 233 ms
265,116 KB
testcase_18 AC 216 ms
264,868 KB
testcase_19 AC 195 ms
265,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>

using namespace std;

template<int NV> class SegTree_Lazy {
  public:
    vector<int> val, to;
    SegTree_Lazy() { val.resize(NV * 2); to.resize(NV * 2); };
    int comp(int l, int r) { return l+r; }

    int getval(int x, int y, int l = 0, int r = NV, int k = 1) {
      if(r<=x || y<=l) return 0;
      if(x<=l && r<=y) return to[k];
      x = max(x, l);
      y = min(y, r);
      if(val[k] >= 0) return val[k] ? (y-x) : 0;
      return comp(getval(x, y, l, (l+r) / 2, k*2), getval(x, y, (l+r) / 2, r, k*2+1));
    }

    void update(int x, int y, int v, int l=0, int r=NV, int k=1) {
      if(l >= r) return;
      if(x<=l && r<=y) {
        val[k] = v;
        to[k] = val[k] ? (r-l) : 0;
      }
      else if(l < y && x < r) {
        if(val[k] != -1) {
          val[k*2] = val[k*2+1] = val[k];
          to[k*2] = to[k*2+1] = val[k] ? (r-l)/2:0;
          val[k] = -1;
        }
        update(x, y, v, l, (l+r)/2, k*2);
        update(x, y, v, (l+r)/2,r,k*2+1);
        to[k] = comp(to[k*2], to[k*2+1]);
      }
    }
};

int N, Q;

typedef long long ll;
ll AA, BB;
SegTree_Lazy<1<<23> st[2];

void solve() {
  int i, j, k, l, r, x, y; string s;
  cin >> N >> Q;
  while(Q--) {
    cin >> x >> l >> r;
    if(x == 0) {
      int a = st[0].getval(l, r+1);
      int b = st[1].getval(l, r+1);

      if(a > b) AA += a;
      if(a < b) BB += b;
    }
    else {
      st[x-1].update(l, r+1, 1);
      st[(x-1)^1].update(l, r+1, 0);
    }
  }
  AA += st[0].getval(0, N);
  BB += st[1].getval(0, N);

  printf("%lld %lld\n", AA, BB);
}

int main() {
  solve(); return 0;
}
0