結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | 赤信号 |
提出日時 | 2024-04-22 20:03:38 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,123 bytes |
コンパイル時間 | 3,998 ms |
コンパイル使用メモリ | 272,204 KB |
実行使用メモリ | 8,320 KB |
最終ジャッジ日時 | 2024-10-14 19:40:23 |
合計ジャッジ時間 | 5,976 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 8 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 4 ms
5,248 KB |
testcase_09 | AC | 59 ms
5,632 KB |
testcase_10 | AC | 55 ms
5,248 KB |
testcase_11 | AC | 48 ms
5,248 KB |
testcase_12 | AC | 60 ms
5,760 KB |
testcase_13 | AC | 11 ms
5,248 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 116 ms
8,192 KB |
testcase_17 | AC | 132 ms
8,192 KB |
testcase_18 | AC | 96 ms
8,320 KB |
testcase_19 | AC | 83 ms
8,192 KB |
ソースコード
#pragma GCC optimize("O3") #ifdef LOCAL #include "algo/debug_ver2.hpp" #else #define _debug(...) 42 #endif #include <bits/stdc++.h> using namespace std; template <typename T, typename U> struct LazySegmentTree { int n; vector<T> nodes; vector<U> lazy; vector<int> sizes; T ti; U ui; function<T(T, T)> op; function<T(T, U, int)> mapping; function<U(U, U)> composition; int bit_width(int x) { int ret = 0; while (x) x >>= 1, ++ret; return ret; } LazySegmentTree(int size, T ti, U ui, function<T(T, T)> op, function<T(T, U, int)> mapping, function<U(U, U)> composition) : ti(ti), ui(ui), op(op), mapping(mapping), composition(composition) { n = 1; while (n < size) n *= 2; nodes.resize(n * 2, ti); lazy.resize(n * 2, ui); sizes.resize(n * 2); for (int i = 0; i < size; ++i) sizes[n + i] = 1; for (int i = n - 1; i > 0; --i) sizes[i] = sizes[i * 2] + sizes[i * 2 + 1]; } LazySegmentTree(vector<T> vec, T ti, U ui, function<T(T, T)> op, function<T(T, U, int)> mapping, function<U(U, U)> composition) : LazySegmentTree(vec.size(), ti, ui, op, mapping, composition) { build(vec); } void build(vector<T> vec) { for (int i = 0; i < n; ++i) nodes[n + i] = vec[i]; for (int i = n - 1; i > 0; --i) update(i); } void set(int k, T x) { k += n; for (int i = bit_width((unsigned int)n) - 1; i > 0; --i) propagate(k >> i); nodes[k] = x; for (int i = 1; i < bit_width((unsigned int)n); ++i) update(k >> i); } T get(int k) { k += n; for (int i = bit_width((unsigned int)n) - 1; i > 0; --i) propagate(k >> i); return nodes[k]; } T prod(int l, int r) { l += n, r += n; for (int i = bit_width((unsigned int)n) - 1; i > 0; --i) { if (((l >> i) << i) != l) propagate(l >> i); if (((r >> i) << i) != r) propagate((r - 1) >> i); } T l_cum = ti, r_cum = ti; for (; l < r; l /= 2, r /= 2) { if (l % 2 == 1) l_cum = op(l_cum, nodes[l++]); if (r % 2 == 1) r_cum = op(r_cum, nodes[--r]); } return op(l_cum, r_cum); } T all_prod() { return nodes[1]; } void apply(int k, U x) { k += n; for (int i = bit_width((unsigned int)n) - 1; i > 0; --i) propagate(k >> i); nodes[k] = mapping(nodes[k], x, sizes[k]); for (int i = 1; i < bit_width((unsigned int)n); ++i) update(k >> i); } void apply(int l, int r, U x) { l += n, r += n; for (int i = bit_width((unsigned int)n) - 1; i > 0; --i) { if (((l >> i) << i) != l) propagate(l >> i); if (((r >> i) << i) != r) propagate((r - 1) >> i); } for (int l2 = l, r2 = r; l2 < r2; l2 /= 2, r2 /= 2) { if (l2 % 2 == 1) all_apply(l2++, x); if (r2 % 2 == 1) all_apply(--r2, x); } for (int i = 1; i < bit_width((unsigned int)n); ++i) { if (((l >> i) << i) != l) update(l >> i); if (((r >> i) << i) != r) update((r - 1) >> i); } } private: void update(int x) { nodes[x] = op(nodes[x * 2], nodes[x * 2 + 1]); } void all_apply(int i, U x) { nodes[i] = mapping(nodes[i], x, sizes[i]); if (i < n) lazy[i] = composition(lazy[i], x); } void propagate(int i) { all_apply(i * 2, lazy[i]); all_apply(i * 2 + 1, lazy[i]); lazy[i] = ui; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, q; cin >> n >> q; LazySegmentTree<array<int, 2>, array<int, 2>> lsgt(n, {0, 0}, {-1, -1}, [](array<int, 2> x, array<int, 2> y) -> array<int, 2> { return {x[0] + y[0], x[1] + y[1]}; }, [](array<int, 2> x, array<int, 2> y, int len) -> array<int, 2> { return y == array<int, 2>{-1, -1} ? x : array<int, 2>{y[0] * len, y[1] * len}; }, [](array<int, 2> x, array<int, 2> y) -> array<int, 2> { return y == array<int, 2>{-1, -1} ? x : y; } ); array<int, 2> scores; for (int _ = 0; _ < q; ++_) { int x, l, r; cin >> x >> l >> r; ++r; if (x == 0) { array<int, 2> counts = lsgt.prod(l, r); if (counts[0] == counts[1]) continue; int tar = max_element(counts.begin(), counts.end()) - counts.begin(); scores[tar] += counts[tar]; } else lsgt.apply(l, r, {x == 1, x == 2}); } scores[0] += lsgt.all_prod()[0]; scores[1] += lsgt.all_prod()[1]; cout << scores[0] << ' ' << scores[1] << '\n'; }