結果

問題 No.230 Splarraay スプラレェーイ
ユーザー tonetone
提出日時 2019-12-01 04:19:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 2,577 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 95,080 KB
実行使用メモリ 7,744 KB
最終ジャッジ日時 2023-08-13 10:20:35
合計ジャッジ時間 4,663 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 14 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 115 ms
5,260 KB
testcase_10 AC 104 ms
4,380 KB
testcase_11 AC 68 ms
4,384 KB
testcase_12 AC 117 ms
5,340 KB
testcase_13 AC 19 ms
4,380 KB
testcase_14 AC 93 ms
7,552 KB
testcase_15 AC 185 ms
7,568 KB
testcase_16 AC 216 ms
7,688 KB
testcase_17 AC 258 ms
7,604 KB
testcase_18 AC 159 ms
7,744 KB
testcase_19 AC 159 ms
7,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

struct LazySegmentTree {
private:
    int n;
    vector<int> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
        lazyFlag.resize(2*n-1, false);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = (r-l)*lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    void update(int a, int b, int x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    int find(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        int vl = find(a, b, 2*k+1, l, (l+r)/2);
        int vr = find(a, b, 2*k+2, (l+r)/2, r);
        return vl+vr;
    }
};


int main(int argc, char const *argv[]) {
  ll n, Q, a, b, c;
  std::cin >> n;
  std::cin >> Q;
  ll A=0, B=0;
  LazySegmentTree s(vector<int>(n, 0)), t(vector<int>(n, 0));
  for(int i=0;i<Q;i++){
    std::cin >> a >> b >> c;
    if(a==0){
      ll p = s.find(b, c+1);
      ll q = t.find(b, c+1);
      if(p>q) A+=p;
      if(p<q) B+=q;
    }else {
      s.update(b, c+1, (a==1?1:0));
      t.update(b, c+1, (a==1?0:1));
    }
    //std::cout << s.find(0, n) << " " << t.find(0, n) << '\n';
  }
  ll p = s.find(0, n);
  ll q = t.find(0, n);
  A+=p, B+=q;
  std::cout << A << " " << B << '\n';
  return 0;
}
0