結果

問題 No.876 Range Compress Query
ユーザー Tatsu_mrTatsu_mr
提出日時 2024-06-12 23:52:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,482 bytes
コンパイル時間 4,855 ms
コンパイル使用メモリ 263,896 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 23:53:07
合計ジャッジ時間 7,640 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 2 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 220 ms
6,944 KB
testcase_12 AC 160 ms
6,944 KB
testcase_13 AC 161 ms
6,940 KB
testcase_14 AC 201 ms
6,944 KB
testcase_15 AC 139 ms
6,940 KB
testcase_16 AC 189 ms
6,940 KB
testcase_17 AC 216 ms
6,944 KB
testcase_18 AC 203 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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);
            if (l > 0) {
                long long x = val.sum(l - 1, l), y = val.sum(l, l + 1);
                if (x == y) {
                    same.add(l - 1, 1);
                }
                if (same.sum(l - 1, l) == 1 && x != y) {
                    same.add(l - 1, -1);
                }
            }
            if (r < n - 1) {
                long long x = val.sum(r, r + 1), y = val.sum(r + 1, r + 2);
                if (x == y) {
                    same.add(r, 1);
                }
                if (same.sum(r, r + 1) == 1 && x != y) {
                    same.add(r, -1);
                }
            }
        } else {
            long long ans = r - l + 1;
            ans -= same.sum(l, r);
            cout << ans << endl;
        }
    }
}
0