結果

問題 No.879 Range Mod 2 Query
コンテスト
ユーザー detteiuu
提出日時 2026-03-15 04:03:30
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,975 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,089 ms
コンパイル使用メモリ 382,024 KB
実行使用メモリ 15,744 KB
最終ジャッジ日時 2026-03-15 04:03:38
合計ジャッジ時間 7,725 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define pass (void)0
#define INF (1<<30)-1
#define INFLL (1LL<<60)-1
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define YesNo(cond) cout << ((cond) ? "Yes\n" : "No\n")
#define YESNO(cond) cout << ((cond) ? "YES\n" : "NO\n")

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;

template <typename T> void print(const T& value) { cout << value << "\n"; }
template <typename T> void print(const vector<T>& vec) { for (auto& v : vec) cout << v << " "; cout << "\n"; }
template <typename T> void input(vector<T>& vec) { for (auto& v : vec) cin >> v; };
template <typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using vm = vector<mint>;

struct Node {
    ll val;
    ll cnt;
    ll size;
};

Node op(Node left, Node right) {
    return {left.val+right.val, left.cnt+right.cnt, left.size+right.size};
}

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

struct Lazy {
    ll d;
    ll m;
    bool flag;
};

Node mapping(Lazy top, Node bottom) {
    bottom.val += top.d*bottom.size;
    if (top.m) {
        bottom.val += bottom.cnt;
        bottom.cnt = bottom.size-bottom.cnt;
    }
    if (top.flag) bottom.val = 0;
    return bottom;
}

Lazy composition(Lazy top, Lazy bottom) {
    bottom.d += top.d;
    if (top.m) {
        if (bottom.m) bottom.d ++;
        bottom.m ^= 1;
    }
    bottom.flag |= top.flag;
    return bottom;
}

Lazy ID() {
    return {0, 0, false};
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    ll N, Q;
    cin >> N >> Q;
    vl A(N);
    input(A);

    vector<Node> def(N);
    rep (i, N) {
        def[i] = {A[i]/2, A[i]%2, 1};
    }
    lazy_segtree<Node, op, e, Lazy, mapping, composition, ID> seg(def);
    rep (i, Q) {
        ll t;
        cin >> t;
        if (t == 1) {
            ll l, r;
            cin >> l >> r;
            l --; r --;
            seg.apply(l, r+1, {0, 0, true});
        } else if (t == 2) {
            ll l, r, x;
            cin >> l >> r >> x;
            l --; r --;
            seg.apply(l, r+1, {x/2, x%2, false});
        } else {
            ll l, r;
            cin >> l >> r;
            l --; r --;
            Node res = seg.prod(l, r+1);
            print(res.val*2+res.cnt);
        }
    }
}
0