結果

問題 No.876 Range Compress Query
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-09-10 10:28:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 3,053 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 201,536 KB
実行使用メモリ 5,204 KB
最終ジャッジ日時 2023-09-15 13:03:24
合計ジャッジ時間 3,761 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 57 ms
4,860 KB
testcase_12 AC 48 ms
4,668 KB
testcase_13 AC 49 ms
4,684 KB
testcase_14 AC 57 ms
4,944 KB
testcase_15 AC 43 ms
4,956 KB
testcase_16 AC 57 ms
5,196 KB
testcase_17 AC 57 ms
5,116 KB
testcase_18 AC 59 ms
5,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V> struct BIT {
    BIT() {}  // [L, R)
    int NV;vector<V> bit;
    BIT(int n){ init(n); }
    void init(int n) { NV = 1; while (NV < n)NV *= 2; bit.resize(NV); clear(); }
    V operator[](int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; }
    void add(int e, V v) { e++; while (e <= NV) bit[e - 1] += v, e += e&-e; }
    int lower_bound(V val) { 
        V tv = 0; int i, ent = 0; for (i = NV - 1; i >= 0; i--)
        if(tv+bit[ent+(1<<i)-1]<=val)tv+=bit[ent+(1<<i)-1],ent += (1 << i);return ent;
    }
    V get(int L, int R) {
        assert(0 <= L); assert(R <= NV); assert(L <= R);
        V res = 0; if(R) res += operator[](R - 1); if (L) res -= operator[](L - 1);return res;
    }
    void clear() { rep(i, 0, NV) bit[i] = 0; }
	void update(int e, V v) { add(e, v - get(e, e + 1)); }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/


int N, Q; ll A[101010];
ll B[101010];
BIT<int> bit(101010);
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> Q;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N - 1) {
        B[i] = A[i + 1] - A[i];
        if(B[i] != 0)
            bit.update(i, 1);
    }

    rep(i, 0, Q)
    {
        int t; cin >> t;
        if(t == 1) {
            int l, r, x;
            cin >> l >> r >> x;
            l--;
            r--;
            if(l) {
                bit.update(l - 1, 0);
                B[l - 1] += x;
                if(B[l - 1] != 0)
                    bit.update(l - 1, 1);
            }
            bit.update(r, 0);
            B[r] -= x;
            if(B[r] != 0)
            bit.update(r, 1);
        }
        else {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            int ans = bit.get(l, r) + 1;
            printf("%d\n", ans);
        }
    }
}

0