結果

問題 No.876 Range Compress Query
ユーザー pockynypockyny
提出日時 2019-09-06 22:02:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 77,136 KB
実行使用メモリ 5,996 KB
最終ジャッジ日時 2023-09-06 23:55:38
合計ジャッジ時間 3,306 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 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 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 196 ms
5,200 KB
testcase_12 AC 162 ms
4,988 KB
testcase_13 AC 163 ms
5,188 KB
testcase_14 AC 193 ms
5,488 KB
testcase_15 AC 140 ms
5,412 KB
testcase_16 AC 188 ms
5,644 KB
testcase_17 AC 188 ms
5,996 KB
testcase_18 AC 201 ms
5,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;
ll n,t[200010] = {},mx = 100000000000000;
void built(){
	for(int i = n-1;i>0;i--){
		t[i] = t[i<<1] + t[i<<1|1];
	}
}

void update(ll p,ll a){
	for(t[p+=n] = a;p>1;p >>= 1){
		t[p>>1] = t[p] + t[p^1];
	}
}

ll query(int l, int r){
	ll mn = 1;
	for(l += n, r += n; l<r; l >>= 1,r >>= 1){
		if(l&1) mn += t[l++];
		if(r&1) mn += t[--r];
	}
	return mn;
}

void write(){
	int i;
	cout << endl;
	for(i=1;i<=10;i++){
		cout << t[i] << " ";
		if(i==1 || i==3 || i==7){
			cout << endl;
		}
	}
	cout << endl;
}
ll a[100010];
int main(){
	int i,j,q;
	cin >> n >> q;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	n--;
	for(i=0;i<n;i++){
		a[i] = a[i] - a[i + 1];
	}
	for(i=0;i<n;i++){
		if(a[i]!=0) t[i + n] = 1;
	}
	built();
	for(i=0;i<q;i++){
		//write();
		int x,y,l,r;
		cin >> y >> l >> r;
		l--; r--;
		if(y==1){
			cin >> x;
			if(l>0){
				a[l - 1] -= x;
				update(l - 1,(a[l - 1]!=0));
			}
			a[r] += x; update(r,(a[r]!=0));
		}else{
			cout << query(l,r) << endl;
		}
	}
	//write();
}
0