結果

問題 No.876 Range Compress Query
ユーザー satashunsatashun
提出日時 2019-09-06 21:31:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,761 bytes
コンパイル時間 1,772 ms
コンパイル使用メモリ 145,988 KB
実行使用メモリ 4,392 KB
最終ジャッジ日時 2023-09-06 22:39:46
合計ジャッジ時間 4,223 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 190 ms
4,376 KB
testcase_12 AC 158 ms
4,384 KB
testcase_13 AC 158 ms
4,392 KB
testcase_14 AC 187 ms
4,380 KB
testcase_15 AC 134 ms
4,376 KB
testcase_16 AC 181 ms
4,376 KB
testcase_17 AC 181 ms
4,376 KB
testcase_18 AC 192 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int MN = 100010;

// 1-indexed, [1, n]
template<class T>
class BIT {
	T bit[MN];
	int n;

public:
	BIT() {
		n = MN;
		memset(bit, 0, sizeof(bit));
	}

	T sum(int i) {
		++i;
		T s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i, T x) {
		++i;
		while (i < n) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

int main() {
	int N, Q;
	cin >> N >> Q;
	vi a(N), df(N-1);
	rep(i, N) {
		cin >> a[i];
	}

	BIT<int> T;

	rep(i, N-1) {
		df[i] = (a[i+1] - a[i]);
		if (df[i] == 0) {
			T.add(i, 1);
		}
	}

	rep(i, Q) {
		int t, l, r; cin >> t >> l >> r;
		--l; --r;
		if (t == 1) {
			int x; cin >> x;
			if (l) {
				if (df[l-1] == 0) {
					T.add(l-1, -1);
				}
				df[l-1] += x;
				if (df[l-1] == 0) {
					T.add(l-1, 1);
				}
			}
			if (r < N-1) {
				if (df[r] == 0) {
					T.add(r, -1);
				}
				df[r] -= x;
				if (df[r] == 0) {
					T.add(r, 1);
				}
			}
		} else {
			int ans = T.sum(r-1) - T.sum(l-1);
			printf("%d\n", r - l + 1 - ans);
		}
	}

	return 0;
}
0