結果

問題 No.876 Range Compress Query
ユーザー definedefine
提出日時 2019-09-08 16:42:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 2,460 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 172,684 KB
実行使用メモリ 6,340 KB
最終ジャッジ日時 2023-09-09 22:33:06
合計ジャッジ時間 4,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 188 ms
5,380 KB
testcase_12 AC 156 ms
5,204 KB
testcase_13 AC 156 ms
5,528 KB
testcase_14 AC 187 ms
5,436 KB
testcase_15 AC 136 ms
5,792 KB
testcase_16 AC 184 ms
5,916 KB
testcase_17 AC 179 ms
6,340 KB
testcase_18 AC 195 ms
5,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


struct BIT {
	int size;
	vector<int>dat, zero;
	void add(int x, int y) {
		while (x <= size) {
			zero[x] += y;
			x += x & -x;
		}
	}
	void add2(int x, int y) {
		if (dat[x] == 0)add(x, -1);
		dat[x] += y;
		if (dat[x] == 0)add(x, 1);
	}
	int sum(int x) {
		int s = 0;
		while (x > 0) {
			s += zero[x];
			x -= x & -x;
		}
		return s;
	}
	BIT(vector<int>x) {
		size = x.size();
		dat.resize(size);
		zero.resize(size, 0);
		rep(i, size - 1) {
			dat[i + 1] = x[i] - x[i + 1];
			if (!dat[i + 1]) {
				add(i + 1, 1);
			}
		}
	}
};
int n, q;
vector<int>v;
signed main() {
	cin >> n >> q;
	v.resize(n);
	rep(i, n)cin >> v[i];

	BIT bit(v);
	rep(_, q) {
		int type; cin >> type;
		if (type == 1) {
			int l, r, x; cin >> l >> r >> x;
			if (l - 1) bit.add2(l - 1, -x);
			if (r < n)bit.add2(r, x);
		}
		else {
			int l, r; cin >> l >> r;
			int a = (l - 1 ? bit.sum(l - 1) : 0);
			int b = (r - 1 ? bit.sum(r - 1) : 0);
			cout << r - l + 1 - (b - a) << endl;
		}
	}
}
0