結果
問題 | No.879 Range Mod 2 Query |
ユーザー | 0w1 |
提出日時 | 2019-10-12 00:44:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,583 bytes |
コンパイル時間 | 2,656 ms |
コンパイル使用メモリ | 217,988 KB |
実行使用メモリ | 94,124 KB |
最終ジャッジ日時 | 2024-05-04 11:29:23 |
合計ジャッジ時間 | 14,666 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:95, from main.cpp:1: In member function 'std::size_t std::valarray<_Tp>::size() const [with _Tp = long int]', inlined from 'std::size_t std::__detail::_BinBase<_Oper, _FirstArg, _SecondArg>::size() const [with _Oper = std::__plus; _FirstArg = std::valarray<long int>; _SecondArg = std::valarray<long int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/valarray_before.h:550:49, inlined from 'std::size_t std::_Expr<_Clos, _Tp>::size() const [with _Clos = std::__detail::_BinClos<std::__plus, std::_ValArray, std::_ValArray, long int, long int>; _Tp = long int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/valarray_after.h:256:29, inlined from 'std::valarray<_Tp>::valarray(const std::_Expr<_Dom, _Tp>&) [with _Dom = std::__detail::_BinClos<std::__plus, std::_ValArray, std::_ValArray, long int, long int>; _Tp = long int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/valarray:711:23, inlined from 'constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = valarray<long int>; _Callable = main()::<lambda(E, E)>&; _Args = {valarray<long int>, valarray<long int>}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/invoke.h:116:38, inlined from 'static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = std::valarray<long int>; _Functor = main()::<lambda(E, E)>; _ArgTypes = {std::valarray<long int>, std::valarray<long int>}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/std_function.h:291:44: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/valarray:938:14: warning: '<unnamed>.std::valarray<long int>::_M_size' is used uninitialized [-Wuninitialized] 9
ソースコード
#include <bits/stdc++.h> using namespace std; template<int n, typename E, typename T, typename FTE, typename FTT, typename FEE> struct Segt { vector<E> dat; vector<T> tag; FTE fte; FTT ftt; FEE fee; E ei; T ti; Segt(FTE a, FTT b, FEE c, E ei, T ti) : fte(a), ftt(b), fee(c), ei(ei), ti(ti) { dat.assign(2 * n, ei); tag.assign(2 * n, ti); } void build(vector<E> a) { a.resize(n, ei); for (int i = 0; i < n; ++i) dat[n + i] = a[i]; for (int i = n - 1; i; --i) dat[i] = fee(dat[i << 1], dat[i << 1 | 1]); } void push(int k) { dat[k] = fte(tag[k], dat[k]); for (int c = 0; k < n && c < 2; ++c) tag[k << 1 | c] = ftt(tag[k], tag[k << 1 | c]); tag[k] = ti; } void update(T t, int ql, int qr, int lb = 0, int rb = n, int k = 1) { push(k); if (qr <= lb || rb <= ql) return; if (ql <= lb && rb <= qr) { tag[k] = t; push(k); return; } int mb = lb + rb >> 1; update(t, ql, qr, lb, mb, k << 1); update(t, ql, qr, mb, rb, k << 1 | 1); dat[k] = fee(dat[k << 1], dat[k << 1 | 1]); } E query(int ql, int qr, int lb = 0, int rb = n, int k = 1) { push(k); if (qr <= lb || rb <= ql) return ei; if (ql <= lb && rb <= qr) return dat[k]; int mb = lb + rb >> 1; return fee(query(ql, qr, lb, mb, k << 1), query(ql, qr, mb, rb, k << 1 | 1)); } }; int main() { ios::sync_with_stdio(false); int N, Q; cin >> N >> Q; vector<int> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } typedef valarray<int64_t> T; // (mtag, stag, atag) typedef valarray<int64_t> E; // (vsum, cnt0, cnt1) function<E(T, E)> fte = [](T f, E e) { if (f[0]) { if (f[1]) swap(e[1], e[2]); e[0] = e[2]; } if (f[2] & 1) swap(e[1], e[2]); e[0] += f[2] * (e[1] + e[2]); return e; }; function<T(T, T)> ftt = [](T f, T t) { return T({ f[0] | t[0], f[0] ? f[1] + t[1] + t[2] & 1 : t[1], f[0] ? f[2] : f[2] + t[2] }); }; function<E(E, E)> fee = [](E l, E r) { return l + r; }; Segt<(1 << 17), E, T, decltype(fte), decltype(ftt), decltype(fee)> tree(fte, ftt, fee, T(3), E(3)); vector<E> ea(N); transform(A.begin(), A.end(), ea.begin(), [&](int v) { return E({ v, ~v & 1, v & 1 }); }); tree.build(ea); while (Q--) { int P, L, R; cin >> P >> L >> R; --L; if (P == 1) { tree.update(T({ 1, 0, 0 }), L, R); } else if (P == 2) { int X; cin >> X; tree.update(T({ 0, 0, X }), L, R); } else { cout << tree.query(L, R)[0] << '\n'; } } return 0; }