結果
問題 | No.255 Splarrraaay スプラーレェーーイ |
ユーザー |
|
提出日時 | 2017-02-07 21:52:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,923 bytes |
コンパイル時間 | 1,102 ms |
コンパイル使用メモリ | 92,768 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-24 20:08:54 |
合計ジャッジ時間 | 3,530 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | RE * 10 |
ソースコード
#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 monoidsint n;vector<M> a;vector<Q> q;function<M (M,M)> append_m; // associativefunction<Q (Q,Q)> append_q; // associative, not necessarily commutativefunction<M (Q,M)> apply; // distributive, associativeM unit_m; // unitQ unit_q; // unitlazy_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;}