結果
問題 | No.945 YKC饅頭 |
ユーザー |
|
提出日時 | 2019-12-09 13:28:39 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 810 ms / 2,000 ms |
コード長 | 3,988 bytes |
コンパイル時間 | 793 ms |
コンパイル使用メモリ | 121,892 KB |
実行使用メモリ | 48,700 KB |
最終ジャッジ日時 | 2024-06-22 03:29:03 |
合計ジャッジ時間 | 17,142 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 74 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop, std.bitmanip;void main() {auto s = readln.split.map!(to!int);auto N = s[0];auto M = s[1];auto A = iota(M).map!(_ => readln.split).array;alias Tp = Tuple!(int, int);auto st = new LazySegmentTree!(Tp, Tp, min, (a,b)=>b, (a,b)=>b, (a,b)=>a, tuple(1<<29,-1), tuple(1<<29,-1))(N+1);foreach_reverse (i; 0..M) {auto l = A[i][0].to!int - 1;auto r = A[i][1].to!int - 1;auto c = A[i][2].front.to!int;st.update(l, r, tuple(i, c));}int y, k, c;foreach (i; 0..N) {auto t = st.query(i, i);if (t[1] == 'Y') y++;else if (t[1] == 'K') k++;else if (t[1] == 'C') c++;}writeln(y, " ", k, " ", c);}/*参考元: https://github.com/yosupo06/dunkelheit/blob/master/source/dkh/datastructure/segtree.d*//*T: 取得クエリで取得する値の型L: 更新クエリで投げる値の型opTT: 2つの区間の結果をマージする関数 (T, T) -> TopTL: クエリを適用する(作用させる)関数 (T, L) -> TopLL: 2つのクエリをまとめる関数 (L, L) -> LopPrd: (L, int) -> 区間の長さに応じて結果を変化させる関数. 区間和とかに使う (L, int) -> TeT: Tの単位元eL: Lの単位元*//*1. 区間代入 / 区間minauto st = new LazySegmentTree!(long, long, min, (a,b)=>b, (a,b)=>b, (a,b)=>a, 1L<<59, 1L<<59)(N);2. 区間加算 / 区間sumauto st = new LazySegmentTree!(long, long, (a,b)=>a+b, (a,b)=>a+b, (a,b)=>a+b, (a,b)=>a*b, 0L, 0L)(N+1);3. 区間加算 / 区間minauto st = new LazySegmentTree!(long, long, min, (a,b)=>a+b, (a,b)=>a+b, (a,b)=>a, 1L<<59, 0L)(N+1);st.table[] = 0L;4. 区間代入 / 区間sumauto st = new LazySegmentTree!(long, long, (a,b)=>a+b, (a,b)=>b, (a,b)=>b, (a,b)=>a*b, 0L, 1L<<59)(N+1);いずれもAOJでverify済.1. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F2. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G3. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_H4. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_I*/class LazySegmentTree(T, L, alias opTT, alias opTL, alias opLL, alias opPrd, T eT, L eL) {T[] table;L[] lazy_;int n;int size;this(int n) {this.n = n;size = 1;while (size <= n) size <<= 1;size <<= 1;table = new T[](size);lazy_ = new L[](size);table[] = eT;lazy_[] = eL;}void push(int i, int a, int b) {if (lazy_[i] == eL) return;table[i] = opTL(table[i], opPrd(lazy_[i], b - a + 1));if (i * 2 + 1 < size) {lazy_[i*2] = opLL(lazy_[i*2], lazy_[i]);lazy_[i*2+1] = opLL(lazy_[i*2+1], lazy_[i]);}lazy_[i] = eL;}T query(int l, int r) {if (l > r) return eT;return query(l, r, 1, 0, n-1);}T query(int l, int r, int i, int a, int b) {if (b < l || r < a) return eT;push(i, a, b);if (l <= a && b <= r) {return table[i];} else {return opTT(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));}}void update(int l, int r, L val) {if (l > r) return;update(l, r, 1, 0, n-1, val);}void update(int l, int r, int i, int a, int b, L val) {if (b < l || r < a) {push(i, a, b);} else if (l <= a && b <= r) {lazy_[i] = opLL(lazy_[i], val);push(i, a, b);} else {push(i, a, b);update(l, r, i*2, a, (a+b)/2, val);update(l, r, i*2+1, (a+b)/2+1, b, val);table[i] = opTT(table[i*2], table[i*2+1]);}}}