#include using namespace std; using VS = vector; using LL = long long; using VI = vector; using VVI = vector; using PII = pair; using PLL = pair; using VL = vector; using VVL = vector; #define ALL(a) begin((a)),end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define SZ(a) int((a).size()) #define SORT(c) sort(ALL((c))) #define RSORT(c) sort(RALL((c))) #define UNIQ(c) (c).erase(unique(ALL((c))), end((c))) #define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++) #define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--) #define debug(x) cerr << #x << ": " << x << endl const int INF = 1e9; const LL LINF = 1e16; const LL MOD = 1000000000000000009; const double PI = acos(-1.0); int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 }; /* ----- 2018/08/27 Problem: yukicoder 255 / Link: http://yukicoder.me/problems/no/255 ----- */ /* ------問題------ Splarrraaay スプラーレェーーイ はSplarraay スプラレェーイの続編であり、配列を塗りつぶすだけの簡単なゲームです。 プレイヤーはチームAとチームBとチームCとチームDとチームEに分かれ、それぞれのチームを表す色で 1 つの配列を塗りつぶし合います。 最終的なスコアはそのチームの色で塗りつぶされた要素の数と、後述するボーナスポイントの和で決まり、スコアが高いチームがゲームの勝者となります。 ルール 長さ N の、何色にも塗られていない配列が与えられる。つまり、全ての要素に対して、それぞれの色の厚みは 0 である。 5 つのチームは配列のある区間 [l,r] をそのチームの色で塗りつぶしていく。 その際、 何色にも塗られていなかった場合は、それのチームの色で塗られ、そのチームの色の厚みが 1 となり、 既にそのチームの色で塗られていた要素に関しては、その色の厚みが 1 だけ増え、 別のチームの色で塗られていた場合は、後から塗られた色で上書きされ、別のチームの色の厚みを 0 とした後、自分のチームの色の厚みが 1 となる。 不定期にボーナスチャンスが与えられる。 ボーナスチャンスでは区間 [l,r] が与えられ、その時点での区間 [l,r] でのチームXの色の厚みの和を Xlr(X=A,B,C,D,E)とすると、この値が最も大きい方のチームに max(Alr,Blr,Clr,Dlr,Elr) のボーナスポイントが与えられる。 値が最も大きい物が複数ある場合、どのチームにもボーナスポイントは与えられない。 時間制限が訪れゲームが終了したとき、配列の全区間 [0,N−1] での、そのチームの色の厚みの和と、それまでに得たボーナスポイントの和がそのチームのスコアとなる。 既にゲームは終了し、後はスコアを計算するだけです。各チームの行動の履歴とボーナスチャンスの詳細が時系列順に与えられるので、最終スコアを算出してください。 -----問題ここまで----- */ /* -----解説等----- ----解説ここまで---- */ struct Node { Node() { fill(colorCnt, colorCnt + 5, 0); } // e Node(long long x) { fill(colorCnt, colorCnt + 5, x); } LL colorCnt[5]; }; struct Lazy { Lazy() :set(0), lazyval(5), lazyCnt(0) {} // lazy e bool set; long long lazyval; LL lazyCnt; }; long long out_range = 0; typedef long long ll; struct LazySegTreeP { long long N; vector dat; vector lazy; inline Node merge(Node& a, Node& b) { Node node; FOR(i, 0, 5) { node.colorCnt[i] = (a.colorCnt[i] + b.colorCnt[i])%MOD; } return node; } void lazy_push(ll k, ll queryL, ll queryR) { if (lazy[k].set == 0)return; assert(lazy[k].lazyval <= 4); // node * lazy int C = lazy[k].lazyval; (dat[k].colorCnt[C] += (queryR - queryL)*lazy[k].lazyCnt%MOD)%=MOD; FOR(i, 0, 5) { if (i == C)continue; dat[k].colorCnt[i] = 0; } if (k < N - 1) { lazy_set(2 * k + 1, lazy[k]); lazy_set(2 * k + 2, lazy[k]); } lazy[k].lazyval = 5; lazy[k].lazyCnt = 0; lazy[k].set = 0; } inline void lazy_set(ll k, const Lazy& val) { lazy[k].set = 1; if (lazy[k].lazyval == val.lazyval) { (lazy[k].lazyCnt += val.lazyCnt)%=MOD; } else { lazy[k].lazyval = val.lazyval; lazy[k].lazyCnt = val.lazyCnt; } } inline void fix(ll k) { dat[k] = merge(dat[k * 2 + 1], dat[k * 2 + 2]); } LazySegTreeP(int _N) { N = 1; while (N < _N)N *= 2; dat = vector(N * 2 - 1); lazy = vector(N * 2 - 1); } ~LazySegTreeP() { vector().swap(dat); vector().swap(lazy); } inline void lazy_update(ll queryL, ll queryR, const Lazy& val, ll k = 0, ll nodeL = 0, ll nodeR = -1) { if (nodeR == -1)nodeR = N; lazy_push(k, nodeL, nodeR); if (nodeR <= queryL || queryR <= nodeL) { return; } if (queryL <= nodeL && nodeR <= queryR) { lazy_set(k, val); lazy_push(k, nodeL, nodeR); return; } ll nodeM = (nodeL + nodeR) / 2; lazy_update(queryL, queryR, val, k * 2 + 1, nodeL, nodeM); lazy_update(queryL, queryR, val, k * 2 + 2, nodeM, nodeR); fix(k); return; } Node query(ll queryL, ll queryR, ll k, ll nodeL, ll nodeR) { lazy_push(k, nodeL, nodeR); if (nodeR <= queryL || queryR <= nodeL) { return Node(out_range); } if (queryL <= nodeL && nodeR <= queryR) { return dat[k]; } ll nodeM = (nodeL + nodeR) / 2; Node vl = query(queryL, queryR, k * 2 + 1, nodeL, nodeM); Node vr = query(queryL, queryR, k * 2 + 2, nodeM, nodeR); return merge(vr, vl); } inline Node query(int a, int b) { return query(a, b, 0, 0, N); } }; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, Q; cin >> N >> Q; LazySegTreeP seg(N); VL points(5, 0); FOR(_, 0, Q) { int x, l, r; cin >> x >> l >> r; if (x == 0) {// bonus Node topNode = seg.query(l, r + 1); LL maxVal = *max_element(topNode.colorCnt, topNode.colorCnt + 5); int cnt = 0, id = 0; FOR(i, 0, 5) { if (maxVal == topNode.colorCnt[i])cnt++,id=i; } if (cnt == 1) { (points[id] += maxVal)%=MOD; } } else { // add x--; Lazy obj; obj.lazyCnt = 1; obj.lazyval = x; seg.lazy_update(l, r + 1, obj); } } Node topNode = seg.query(0, N); FOR(i, 0, 5) { (points[i] += topNode.colorCnt[i]) %= MOD; cout << points[i] << " \n"[i == 4]; } return 0; }