結果

問題 No.230 Splarraay スプラレェーイ
ユーザー tonegawatonegawa
提出日時 2020-08-20 14:21:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 5,000 ms
コード長 2,577 bytes
コンパイル時間 1,704 ms
コンパイル使用メモリ 123,720 KB
実行使用メモリ 7,916 KB
最終ジャッジ日時 2024-04-21 10:36:14
合計ジャッジ時間 4,778 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 14 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 120 ms
5,472 KB
testcase_10 AC 107 ms
5,376 KB
testcase_11 AC 69 ms
5,376 KB
testcase_12 AC 119 ms
5,600 KB
testcase_13 AC 20 ms
5,376 KB
testcase_14 AC 97 ms
7,840 KB
testcase_15 AC 189 ms
7,852 KB
testcase_16 AC 222 ms
7,792 KB
testcase_17 AC 263 ms
7,664 KB
testcase_18 AC 161 ms
7,664 KB
testcase_19 AC 162 ms
7,916 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