結果

問題 No.876 Range Compress Query
ユーザー Tatsu_mr
提出日時 2024-06-12 23:29:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,328 bytes
コンパイル時間 4,587 ms
コンパイル使用メモリ 252,688 KB
最終ジャッジ日時 2025-02-21 21:24:16
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 RE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n, q;
    cin >> n >> q;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    fenwick_tree<long long> same(n), val(n + 1);
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i + 1]) {
            same.add(i, 1);
        }
    }
    for (int i = 0; i < n; i++) {
        val.add(i, a[i]);
        val.add(i + 1, -a[i]);
    }
    while (q--) {
        int t, l, r;
        cin >> t >> l >> r;
        l--;
        r--;
        if (t == 1) {
            long long x;
            cin >> x;
            val.add(l, x);
            val.add(r + 1, -x);
            long long LL = val.sum(l - 1, l), L = val.sum(l, l + 1), R = val.sum(r, r + 1), RR = val.sum(r + 1, r + 2);
            if (LL == L) {
                same.add(l - 1, 1);
            }
            if (same.sum(l - 1, l) == 1 && LL != L) {
                same.add(l - 1, -1);
            }
            if (R == RR) {
                same.add(r, 1);
            }
            if (same.sum(r, r + 1) == 1 && R != RR) {
                same.add(r, -1);
            }
        } else {
            long long ans = r - l + 1;
            ans -= same.sum(l, r);
            cout << ans << endl;
        }
    }
}
0