結果

問題 No.879 Range Mod 2 Query
ユーザー milanis48663220milanis48663220
提出日時 2023-08-08 00:45:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,778 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 127,952 KB
実行使用メモリ 15,220 KB
最終ジャッジ日時 2024-04-25 18:48:53
合計ジャッジ時間 4,022 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 167 ms
14,864 KB
testcase_20 AC 161 ms
14,828 KB
testcase_21 AC 168 ms
14,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/lazysegtree>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

struct S{
    ll len, sum, odd;
    S(ll len, ll sum, ll odd): len(len), sum(sum), odd(odd) {}
};

struct T{
    int p;
    ll add1;
    bool mod2;
    T(int p, bool mod2, ll add1): p(p), mod2(mod2), add1(add1) {}
};

S op(S x, S y){
    return S(x.len+y.len, x.sum+y.sum, x.odd+y.odd);
}

S e(){
    return S(0, 0, 0);
}

T id(){
    return T(0, false, 0);
}

S mapping(T f, S x){
    
    if(f.mod2){
        x.sum += f.p*x.len;
        if(f.p == 1){
            x.odd = x.len-x.odd;
        }
        x.sum = x.odd;
    }
    x.sum += f.add1*x.len;
    if(f.add1%2 == 1){
        x.odd = x.len-x.odd;
    }
    return x;
}

T composition(T f, T g){
    if(f.mod2){
        g.add1 += f.p;
        g.p ^= (g.add1+f.p)%2;
        g.mod2 = true;
        g.add1 = 0;
    }
    g.add1 += f.add1;
    return g;
}

using Seg = atcoder::lazy_segtree<S, op, e, T, mapping, composition, id>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, q; cin >> n >> q;
    vector<S> s;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        s.push_back(S(1, a, a%2));
    }
    Seg seg(s);
    while(q--){
        int t, l, r; cin >> t >> l >> r; l--;
        if(t == 1){
            seg.apply(l, r, T(0, true, 0));
        }else if(t == 2){
            int x; cin >> x;
            seg.apply(l, r, T(0, false, x));
        }else{
            auto s = seg.prod(l, r);
            cout << s.sum << endl;
        }
        // for(int i = 0; i < n; i++) cout << seg.get(i).sum << ' ';
        // cout << endl;
    }
}
0