結果

問題 No.230 Splarraay スプラレェーイ
ユーザー mayoko_mayoko_
提出日時 2015-07-20 22:09:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 2,594 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 92,012 KB
実行使用メモリ 7,360 KB
最終ジャッジ日時 2023-09-22 20:47:39
合計ジャッジ時間 3,198 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,092 KB
testcase_01 AC 4 ms
7,144 KB
testcase_02 AC 5 ms
7,256 KB
testcase_03 AC 4 ms
7,172 KB
testcase_04 AC 5 ms
7,268 KB
testcase_05 AC 6 ms
7,280 KB
testcase_06 AC 11 ms
7,264 KB
testcase_07 AC 6 ms
7,100 KB
testcase_08 AC 7 ms
7,328 KB
testcase_09 AC 44 ms
7,148 KB
testcase_10 AC 70 ms
7,100 KB
testcase_11 AC 32 ms
7,224 KB
testcase_12 AC 43 ms
7,100 KB
testcase_13 AC 13 ms
7,100 KB
testcase_14 AC 39 ms
7,168 KB
testcase_15 AC 91 ms
7,216 KB
testcase_16 AC 83 ms
7,104 KB
testcase_17 AC 86 ms
7,328 KB
testcase_18 AC 74 ms
7,360 KB
testcase_19 AC 68 ms
7,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef complex<double> C;

enum class color {mine, yours, invalid};
const int MAXN = (1<<17);

struct SegTreeLazy {
    vector<int> val;
    vector<color> lazy;

    SegTreeLazy() {val.resize(2*MAXN); lazy.resize(2*MAXN, color::invalid);}

    int get(int x, int y, int l = 0, int r = MAXN, 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) {
            if (lazy[k] == color::mine) return y-x;
            else return 0;
        }
        return get(x, y, l, (l+r)/2, 2*k) + get(x, y, (l+r)/2, r, 2*k+1);
    }

    void update(int x, int y, color col, int l = 0, int r = MAXN, 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];
        }
    }
};

SegTreeLazy seg[2];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N;
    cin >> Q;
    ll A = 0, B = 0;
    while (Q--) {
        int x, l, r;
        cin >> x >> l >> r;
        if (x == 0) {
            int a = seg[0].get(l, r+1);
            int b = seg[1].get(l, r+1);
            if (a < b) B += b;
            else if (a > b) A += a;
        } else if (x == 1) {
            seg[0].update(l, r+1, color::mine);
            seg[1].update(l, r+1, color::yours);
        } else {
            seg[1].update(l, r+1, color::mine);
            seg[0].update(l, r+1, color::yours);
        }
    }
    A += seg[0].get(0, N+1);
    B += seg[1].get(0, N+1);
    cout << A << " " << B << endl;
    return 0;
}
0