結果

問題 No.876 Range Compress Query
ユーザー ransewhaleransewhale
提出日時 2019-09-06 22:12:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,240 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 164,424 KB
実行使用メモリ 5,476 KB
最終ジャッジ日時 2023-09-07 00:33:41
合計ジャッジ時間 3,762 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 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,388 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 101 ms
5,100 KB
testcase_12 AC 81 ms
5,080 KB
testcase_13 AC 84 ms
5,084 KB
testcase_14 AC 98 ms
5,112 KB
testcase_15 AC 74 ms
5,160 KB
testcase_16 AC 98 ms
5,476 KB
testcase_17 AC 99 ms
5,252 KB
testcase_18 AC 105 ms
5,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n,segtree[410410];
ll a[100100];

void update(int p, int v, int l=0, int r=n, int i=0){
	int vl,vr;
	if(p<l || r<=p){
		return;
	}else if(r-l>1){
		update(p,v,l,(l+r)>>1,i*2+1);
		update(p,v,(l+r)>>1,r,i*2+2);
		segtree[i] = segtree[i*2+1]+segtree[i*2+2];
	}else{
		a[p] += v;
		if(a[p]){
			segtree[i] = 1;
		}else{
			segtree[i] = 0;
		}
	}
}

int query(int p, int q, int l=0, int r=n, int i=0){
	int vl,vr;
	if(q<=l || r<=p){
		return 0;
	}else if(p<=l && r<=q){
		return segtree[i];
	}else{
		vl = query(p,q,l,(l+r)>>1,i*2+1);
		vr = query(p,q,(l+r)>>1,r,i*2+2);
		return vl+vr;
	}
}

int main(void){
	int q,i,t,l,r,x;
	scanf("%d%d",&n,&q);
	for(i=0; i<n; ++i){
		scanf("%d",&x);
		a[i+1] -= x;
		update(i,x);
	}
	for(i=0; i<q; ++i){
		scanf("%d%d%d",&t,&l,&r);
		--t;
		if(t){
			printf("%d\n",query(l,r)+1);
		}else{
			--l;
			scanf("%d",&x);
			update(l,x);
			update(r,-x);
		}
	}
	return 0;
}
0