結果
問題 | No.255 Splarrraaay スプラーレェーーイ |
ユーザー | kimiyuki |
提出日時 | 2017-02-07 21:52:58 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,923 bytes |
コンパイル時間 | 1,081 ms |
コンパイル使用メモリ | 93,032 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-07 00:33:05 |
合計ジャッジ時間 | 3,876 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <array> #include <functional> #include <cmath> #include <cassert> #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) using ll = long long; using namespace std; template <typename M, typename Q> struct lazy_propagation_segment_tree { // on monoids int n; vector<M> a; vector<Q> q; function<M (M,M)> append_m; // associative function<Q (Q,Q)> append_q; // associative, not necessarily commutative function<M (Q,M)> apply; // distributive, associative M unit_m; // unit Q unit_q; // unit lazy_propagation_segment_tree() = default; lazy_propagation_segment_tree(int a_n, M a_unit_m, Q a_unit_q, function<M (M,M)> a_append_m, function<Q (Q,Q)> a_append_q, function<M (Q,M)> a_apply) { n = pow(2,ceil(log2(a_n))); a.resize(2*n-1, a_unit_m); q.resize(max(0, 2*(n-1)-1), a_unit_q); unit_m = a_unit_m; unit_q = a_unit_q; append_m = a_append_m; append_q = a_append_q; apply = a_apply; } void range_apply(int l, int r, Q z) { assert (0 <= l and l <= r and r <= n); range_apply(0, 0, n, l, r, z); } void range_apply(int i, int il, int ir, int l, int r, Q z) { if (l <= il and ir <= r) { a[i] = apply(z, a[i]); if (i < q.size()) q[i] = append_q(z, q[i]); } else if (ir <= l or r <= il) { // nop } else { range_apply(2*i+1, il, (il+ir)/2, 0, n, q[i]); range_apply(2*i+1, il, (il+ir)/2, l, r, z); range_apply(2*i+2, (il+ir)/2, ir, 0, n, q[i]); range_apply(2*i+2, (il+ir)/2, ir, l, r, z); a[i] = append_m(a[2*i+1], a[2*i+2]); q[i] = unit_q; } } M range_concat(int l, int r) { assert (0 <= l and l <= r and r <= n); return range_concat(0, 0, n, l, r); } M range_concat(int i, int il, int ir, int l, int r) { if (l <= il and ir <= r) { return a[i]; } else if (ir <= l or r <= il) { return unit_m; } else { return apply(q[i], append_m( range_concat(2*i+1, il, (il+ir)/2, l, r), range_concat(2*i+2, (il+ir)/2, ir, l, r))); } } }; struct state_t { int size; array<ll,5> acc; }; struct query_t { enum { UNIT, INIT, FILL } type; int color; }; int main() { int n; cin >> n; lazy_propagation_segment_tree<state_t,query_t> segtree(n, (state_t) { 0, {} }, (query_t) { query_t::UNIT }, [&](state_t const & a, state_t const & b) { state_t c; c.size = a.size + b.size; repeat (i,5) c.acc[i] = a.acc[i] + b.acc[i]; return c; }, [&](query_t q, query_t p) { if (q.type == query_t::UNIT) return p; return q; }, [&](query_t p, state_t a) { if (p.type == query_t::UNIT) return a; if (p.type == query_t::INIT) return (state_t) { 1, {} }; state_t b = {}; b.size = a.size; b.acc[p.color] = a.acc[p.color] + a.size; return b; }); repeat (i,n) segtree.range_apply(i, i+1, (query_t) { query_t::INIT }); ll acc[5] = {}; int q; cin >> q; while (q --) { int x, l, r; cin >> x >> l >> r; ++ r; if (x == 0) { state_t it = segtree.range_concat(l, r); auto i = whole(max_element, it.acc); if (whole(count, it.acc, *i) == 1) { acc[i - it.acc.begin()] += *i; } } else { segtree.range_apply(l, r, (query_t) { query_t::FILL, x-1 }); } } state_t it = segtree.range_concat(0, n); repeat (i,5) acc[i] += it.acc[i]; repeat (i,5) cout << acc[i] << ' '; cout << endl; return 0; }