結果

問題 No.833 かっこいい電車
ユーザー pockynypockyny
提出日時 2019-05-24 22:41:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,103 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 69,644 KB
実行使用メモリ 5,880 KB
最終ジャッジ日時 2023-09-14 20:54:35
合計ジャッジ時間 3,698 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
4,644 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 10 ms
4,380 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 117 ms
4,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;
using ll = long long;
ll n,q,t[200010] = {};
int l[100010],r[100010];
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 sum = 0;
	for(l += n, r += n; l<r; l >>= 1,r >>= 1){
		if(l&1) sum += t[l++];
		if(r&1) sum += t[--r];
	}
	return sum;
}

int le(int x){
	if(l[x]) return x;
	int a = 0,b = x;
	while(b - a>1){
		int mid = (a + b)/2;
		if(l[mid]) a = mid;
		else b = mid;
	}
	return a;
}

int ri(int x){
	if(r[x]) return x;
	int a = x,b = n - 1;
	while(b - a>1){
		int mid = (a + b)/2;
		if(r[mid]) b = mid;
		else a = mid;
	}
	return b;
}

int main(){
	int i;
	cin >> n >> q;
	for(i=0;i<n;i++){
		int a; cin >> a; t[i + n] = a;
		l[i] = 1; r[i] = 1;
	}
	built();
	for(i=0;i<q;i++){
		int w,x;
		cin >> w >> x; x--;
		if(w==1){
			r[x] = 0; l[x + 1] = 0;
		}
		if(w==2){
			r[x] = 1; l[x + 1] = 1;
		}
		if(w==3){
			update(x,1);
		}
		if(w==4){
			cout << query(le(x),ri(x) + 1) << endl;
		}
	}
}
	
0