結果

問題 No.879 Range Mod 2 Query
ユーザー t98slidert98slider
提出日時 2023-05-12 03:59:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 3,000 ms
コード長 1,256 bytes
コンパイル時間 5,538 ms
コンパイル使用メモリ 232,864 KB
実行使用メモリ 14,552 KB
最終ジャッジ日時 2023-08-18 16:17:13
合計ジャッジ時間 7,847 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,356 KB
testcase_03 AC 3 ms
4,356 KB
testcase_04 AC 3 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 3 ms
4,356 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,356 KB
testcase_10 AC 3 ms
4,356 KB
testcase_11 AC 128 ms
14,040 KB
testcase_12 AC 76 ms
13,972 KB
testcase_13 AC 99 ms
14,032 KB
testcase_14 AC 87 ms
14,508 KB
testcase_15 AC 91 ms
9,128 KB
testcase_16 AC 124 ms
14,508 KB
testcase_17 AC 126 ms
14,488 KB
testcase_18 AC 128 ms
14,552 KB
testcase_19 AC 113 ms
14,504 KB
testcase_20 AC 112 ms
14,484 KB
testcase_21 AC 128 ms
14,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

using S = array<ll, 3>;
using F = array<ll, 3>;
S e(){return S({0, 0, 0});}
S op(S l, S r){
    for(int i = 0; i < 3; i++) l[i] += r[i];
    return l;
}

S mapping(F f, S x){
    S res{};
    if(f[1] & 1) swap(x[0], x[1]);
    x[2] += (x[0] + x[1]) * f[1];
    if(f[0] == 1) x[2] = x[1];
    if(f[2] & 1) swap(x[0], x[1]);
    x[2] += (x[0] + x[1]) * f[2];
    return x;
}
F composition(F f, F g){
    if(f[0] == 0) return S({g[0], g[1], g[2] + f[1] + f[2]});
    return S({1, g[1] + g[2] + f[1], f[2]});
}
F id(){return F({0, 0, 0});}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    vector<S> tmp(N);
    for(int i = 0; i < N; i++){
        int v;
        cin >> v;
        tmp[i] = S({1 - v % 2, v % 2, v});
    }
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(tmp);
    while(Q--){
        int cmd, l, r, x;
        cin >> cmd >> l >> r;
        l--;
        if(cmd == 1){
            seg.apply(l, r, F({1, 0, 0}));
        }else if(cmd == 2){
            cin >> x;
            seg.apply(l, r, F({0, 0, x}));
        }else{
            cout << seg.prod(l, r)[2] << '\n';
        }
    }
}
0