結果

問題 No.511 落ちゲー 〜手作業のぬくもり〜
ユーザー PachicobuePachicobue
提出日時 2017-12-31 05:37:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,418 ms / 4,000 ms
コード長 9,446 bytes
コンパイル時間 3,460 ms
コンパイル使用メモリ 228,372 KB
実行使用メモリ 14,636 KB
最終ジャッジ日時 2023-08-16 03:09:51
合計ジャッジ時間 10,133 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,388 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 7 ms
4,380 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 1,418 ms
14,360 KB
testcase_30 AC 1,204 ms
13,916 KB
testcase_31 AC 880 ms
13,056 KB
testcase_32 AC 686 ms
14,044 KB
testcase_33 AC 189 ms
7,612 KB
testcase_34 AC 280 ms
6,512 KB
testcase_35 AC 662 ms
14,404 KB
testcase_36 AC 663 ms
14,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}


template <typename T>
vector<T> Vec(int n, T v)
{
    return vector<T>(n, v);
}
template <class... Args>
auto Vec(int n, Args... args)
{
    auto val = Vec(args...);
    return vector<decltype(val)>(n, move(val));
}

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;

template <typename Base>
class SegmentTree
{
public:
    using BaseAlgebra = Base;
    using AccMonoid = typename BaseAlgebra::AccMonoid;
    using OpMonoid = typename BaseAlgebra::OpMonoid;
    using T = typename BaseAlgebra::T;
    using F = typename BaseAlgebra::OpMonoid::T;

    SegmentTree(const int n) : data_num(n), size(1 << (1 + __lg(2 * data_num - 1))), half(size >> 1), value(size, AccMonoid::identity()), action(size, OpMonoid::identity()) { assert(n > 0); }
    SegmentTree(const std::vector<T>& val) : data_num(val.size()), size(1 << (1 + __lg(2 * data_num - 1))), half(size >> 1), value(size), action(size, OpMonoid::identity())
    {
        for (int data = 0; data < half; data++) {
            if (data < data_num) {
                value[data + half] = val[data];
            } else {
                value[data + half] = AccMonoid::identity();
            }
        }
        for (int node = half - 1; node >= 1; node--) {
            value[node] = acc(value[2 * node], value[2 * node + 1]);
        }
    }

    void initialize()
    {
        for (int i = 0; i < size; i++) {
            value[i] = AccMonoid::identity();
            action[i] = OpMonoid::identity();
        }
    }

    void initialize(const vector<T>& val)
    {
        for (int data = 0; data < half; data++) {
            if (data < data_num) {
                value[data + half] = val[data];
            } else {
                value[data + half] = AccMonoid::identity();
            }
        }
        for (int node = half - 1; node >= 1; node--) {
            value[node] = acc(value[2 * node], value[2 * node + 1]);
        }
    }

    T get(const int a) const
    {
        assert(0 <= a and a < data_num);
        return accumulate(a, a + 1);
    }

    void set(const int a, const T& val)
    {
        assert(0 <= a and a < data_num);
        const int node = a + half;
        value[node] = val;
        for (int i = node / 2; i > 0; i /= 2) {
            value[i] = acc(value[2 * i], value[2 * i + 1]);
        }
    }

    T accumulate(const int a, const int b) const  // Accumulate (a,b]
    {
        assert(0 <= a and a < b and b <= data_num);
        return accumulateRec(1, 0, half, a, b);
    }

    void modify(const int a, const int b, const F& f)  // Apply f on (a,b]
    {
        assert(0 <= a and a < b and b <= data_num);
        if (f == OpMonoid::identity()) {
            return;
        }
        modifyRec(1, 0, half, a, b, f);
    }

    int query(const int a, const int b) const  // query (a,b]
    {
        assert(0 <= a and a < b and b <= data_num);
        return queryRec(1, 0, half, a, b);
    }

private:
    void modifyRec(const int range_index, const int range_left, const int range_right, const int op_left, const int op_right, const F& f)
    {
        if (op_left <= range_left and range_right <= op_right) {
            value[range_index] = act(f, value[range_index]);
            action[range_index] = compose(f, action[range_index]);
        } else if (range_right <= op_left or op_right <= range_left) {
            // Do nothing
        } else {
            modifyRec(2 * range_index, range_left, (range_left + range_right) / 2, 0, half, action[range_index]);
            modifyRec(2 * range_index, range_left, (range_left + range_right) / 2, op_left, op_right, f);
            modifyRec(2 * range_index + 1, (range_left + range_right) / 2, range_right, 0, half, action[range_index]);
            modifyRec(2 * range_index + 1, (range_left + range_right) / 2, range_right, op_left, op_right, f);
            value[range_index] = acc(value[2 * range_index], value[2 * range_index + 1]);
            action[range_index] = OpMonoid::identity();
        }
    }

    T accumulateRec(const int range_index, const int range_left, const int range_right, const int op_left, const int op_right) const
    {
        if (op_left <= range_left and range_right <= op_right) {
            return value[range_index];
        } else if (range_right <= op_left or op_right <= range_left) {
            return AccMonoid::identity();
        } else {
            return act(action[range_index], acc(accumulateRec(2 * range_index, range_left, (range_left + range_right) / 2, op_left, op_right),
                                                accumulateRec(2 * range_index + 1, (range_left + range_right) / 2, range_right, op_left, op_right)));
        }
    }

    int queryRec(const int range_index, const int range_left, const int range_right, const int op_left, const int op_right) const
    {
        if (op_left <= range_left and range_right <= op_right) {
            return value[range_index];
        } else if (range_right <= op_left or op_right <= range_left) {
            return AccMonoid::identity();
        } else {
            return queryRec(2 * range_index, range_left, (range_left + range_right) / 2, op_left, op_right) + queryRec(2 * range_index + 1, (range_left + range_right) / 2, range_right, op_left, op_right);
        }
    }

    const int data_num;  // Num of valid data on leaves.
    const int size;
    const int half;
    vector<T> value;   // Tree for value(length: size)
    vector<F> action;  // Tree for action(length: half)
    bool has_lazy;

    const AccMonoid acc{};
    const OpMonoid compose{};
    const BaseAlgebra act{};
};
struct Sum_Plus {
    using T = ll;

    struct AccMonoid {
        T operator()(const T& a, const T& b) const { return a + b; }
        static constexpr T identity() { return 0; }
    };

    struct OpMonoid {
        using T = ll;
        T operator()(const T& f1, const T& f2) const { return f1 + f2; }
        static constexpr T identity() { return 0; }
    };

    T operator()(const OpMonoid::T& f, const T& x) const { return f + x; }
};

template <typename Data, typename Checker>
void ParallelBinarySearch(const vector<Data>& queries, Checker& checker, const int inf, const int sup, vector<int>& ans)
{
    const int Q = queries.size();
    ans.resize(Q, INF<int>);
    using Query = pair<Data, int>;
    struct Qset {
        int l;
        int r;
        vector<Query> query;
    };
    vector<Qset> data{Qset{inf, sup, vector<Query>(Q)}};
    for (int i = 0; i < Q; i++) {
        data[0].query[i] = make_pair(queries[i], i);
    }
    for (int d = 0;; d++) {
        if (data.empty()) {
            break;
        }
        vector<Qset> next;
        checker.initialize();
        int pos = 0;
        for (const auto& dat : data) {
            const int inf = dat.l;
            const int sup = dat.r;
            const int mid = (inf + sup) / 2;
            Qset former{inf, mid, vector<Query>{}};
            Qset latter{mid + 1, sup, vector<Query>{}};
            for (; pos < mid; pos++) {
                checker.update(pos);
            }
            if (inf >= sup - 1) {
                for (const auto& e : dat.query) {
                    if (checker.check(e.first)) {
                        ans[e.second] = inf;
                    } else if (inf == sup - 1) {
                        latter.query.push_back(e);
                    }
                }
            } else {
                for (const auto& e : dat.query) {
                    if (checker.check(e.first)) {
                        former.query.push_back(e);
                    } else {
                        latter.query.push_back(e);
                    }
                }
            }
            if (not former.query.empty()) {
                next.push_back(former);
            }
            if (not latter.query.empty()) {
                next.push_back(latter);
            }
        }
        data = next;
    }
}

using Data = int;
struct Op {
    ll a;
    ll b;
    ll x;
};

vector<Op> op;
int N;
ll H;
ll W;

// Checker::initialize() => void
// Checker::update(int pos) => void
// Checker::check(const Data&) => bool
struct Checker {
    Checker() : seg(W) {}
    void initialize()
    {
        seg.initialize();
    }
    void update(const int pos)
    {
        const auto& q = op[pos];
        const ll l = q.x;
        const ll r = q.a + q.x;
        seg.modify(l, r, q.b);
    }
    bool check(const Data& data)
    {
        return seg.get(data) >= H;
    }
    SegmentTree<Sum_Plus> seg;
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    cin >> W >> H;
    vector<Data> queries(W);
    for (int i = 0; i < W; i++) {
        queries[i] = i;
    }
    for (int i = 0; i < N; i++) {
        ll a, b, x;
        cin >> a >> b >> x;
        x--;
        op.push_back(Op{a, b, x});
    }
    Checker checker;
    vector<int> ans;
    ParallelBinarySearch(queries, checker, 0, N, ans);

    ll a = 0;
    ll b = 0;
    for (int i = 0; i < W; i++) {
        (ans[i] % 2 == 0 ? b : a)++;
    }
    show(ans);
    cout << (a == b ? "DRAW" : a < b ? "B" : "A") << endl;

    return 0;
}
0