結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | nebukuro09 |
提出日時 | 2017-04-07 16:08:59 |
言語 | D (dmd 2.106.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,422 bytes |
コンパイル時間 | 704 ms |
コンパイル使用メモリ | 119,860 KB |
実行使用メモリ | 16,424 KB |
最終ジャッジ日時 | 2024-06-12 18:37:32 |
合計ジャッジ時間 | 8,788 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 13 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 4 ms
6,944 KB |
testcase_09 | AC | 591 ms
6,940 KB |
testcase_10 | AC | 109 ms
6,940 KB |
testcase_11 | AC | 66 ms
6,944 KB |
testcase_12 | AC | 608 ms
6,940 KB |
testcase_13 | AC | 19 ms
6,944 KB |
testcase_14 | TLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
ソースコード
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; void main() { auto N = readln.chomp.to!int; auto Q = readln.chomp.to!int; auto st = new LazySegmentTree!(int, (a,b)=>a+b)(N); auto st2 = new LazySegmentTree!(int, (a,b)=>a+b)(N); long score1 = 0; long score2 = 0; foreach (q; 0..Q) { auto s = readln.split.map!(to!int); auto x = s[0]; auto l = s[1]; auto r = s[2]; if (x == 0) { auto used = st2.getVal(l, r); auto m = st.getVal(l, r); auto a = (used + m) / 2; auto b = used - a; if (m > 0) score1 += a; if (m < 0) score2 += b; } else if (x == 1) { st.assign(l, r, 1); st2.assign(l, r, 1); } else if (x == 2) { st.assign(l, r, -1); st2.assign(l, r, 1); } } auto used = st2.getVal(0, N-1); auto m = st.getVal(0, N-1); auto a = (used + m) / 2; auto b = used - a; score1 += a; score2 += b; writeln(score1, " ", score2); } class LazySegmentTree(T, alias op) { T[] table; T[] lazy_; int size; this(int n) { assert(bsr(n) < 29); size = 1 << (bsr(n) + 2); table = new T[](size); lazy_ = new T[](size); fill(table, 0); fill(lazy_, 0); } void assign(int left, int right, T num) { return assign(left, right, num, 0, 0, size/2-1); } void assign(int left, int right, T num, int i, int seg_left, int seg_right) { if (left > seg_right || right < seg_left) { return; } if (lazy_[i] == num) return; if (left <= seg_left && seg_right <= right) { lazy_[i] = num; return; } else { if (lazy_[i] != 0) { lazy_[i*2+1] = lazy_[i]; lazy_[i*2+2] = lazy_[i]; lazy_[i] = 0; } assign(left, right, num, i*2+1, seg_left, (seg_left+seg_right)/2); assign(left, right, num, i*2+2, (seg_left+seg_right)/2+1, seg_right); } } T getVal(int left, int right) { return getVal(left, right, 0, 0, size/2-1); } T getVal(int left, int right, int i, int seg_left, int seg_right) { if (left > seg_right || right < seg_left) { return 0; } else if (seg_left == seg_right) { if (lazy_[i] != 0) { table[i] = lazy_[i]; lazy_[i] = 0; } return table[i]; } else if (left <= seg_left && seg_right <= right) { if (lazy_[i] != 0) { lazy_[i*2+1] = lazy_[i]; lazy_[i*2+2] = lazy_[i]; table[i] = lazy_[i] * (seg_right - seg_left + 1); lazy_[i] = 0; return table[i]; } } if (lazy_[i] != 0) { lazy_[i*2+1] = lazy_[i]; lazy_[i*2+2] = lazy_[i]; lazy_[i] = 0; } table[i] = op(getVal(left, right, i*2+1, seg_left, (seg_left+seg_right)/2), getVal(left, right, i*2+2, (seg_left+seg_right)/2+1, seg_right)); return table[i]; } }