結果

問題 No.833 かっこいい電車
ユーザー leaf_1415leaf_1415
提出日時 2019-05-24 23:21:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,319 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 70,260 KB
実行使用メモリ 10,428 KB
最終ジャッジ日時 2023-09-14 20:56:52
合計ジャッジ時間 4,578 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
7,928 KB
testcase_01 AC 3 ms
4,948 KB
testcase_02 AC 3 ms
4,952 KB
testcase_03 AC 3 ms
4,936 KB
testcase_04 AC 3 ms
5,104 KB
testcase_05 AC 4 ms
5,088 KB
testcase_06 AC 3 ms
5,144 KB
testcase_07 AC 3 ms
4,900 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
5,044 KB
testcase_10 AC 126 ms
8,056 KB
testcase_11 AC 167 ms
9,596 KB
testcase_12 AC 52 ms
6,920 KB
testcase_13 AC 37 ms
5,752 KB
testcase_14 AC 135 ms
9,596 KB
testcase_15 AC 66 ms
7,752 KB
testcase_16 AC 54 ms
8,700 KB
testcase_17 AC 48 ms
5,424 KB
testcase_18 AC 153 ms
8,576 KB
testcase_19 AC 53 ms
8,068 KB
testcase_20 AC 15 ms
6,224 KB
testcase_21 AC 126 ms
6,544 KB
testcase_22 AC 92 ms
10,428 KB
testcase_23 AC 60 ms
8,268 KB
testcase_24 AC 90 ms
9,560 KB
testcase_25 AC 143 ms
7,712 KB
testcase_26 AC 64 ms
8,504 KB
testcase_27 AC 104 ms
8,056 KB
testcase_28 AC 75 ms
6,496 KB
testcase_29 AC 91 ms
7,664 KB
testcase_30 AC 92 ms
10,408 KB
testcase_31 AC 143 ms
7,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <vector>
#define llint long long

using namespace std;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = 0;
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = (seg[i*2] + seg[i*2+1]);
		}
	}

	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return 0;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return (lval + rval);
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, Q;
llint a[100005];
set<llint> S;
SegTree seg(17);

int main(void)
{
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) S.insert(i);
	S.insert(n+1);
	for(int i = 1; i <= n; i++) seg.update(i, a[i]);
	
	llint t, x;
	for(int q = 0; q < Q; q++){
		cin >> t >> x;
		if(t == 1) S.erase(x+1);
		if(t == 2) S.insert(x+1);
		if(t == 3) seg.update(x, seg.query(x, x)+1);
		if(t == 4){
			auto p = S.upper_bound(x);
			llint r = *p; p--;
			llint l = *p;
			cout << seg.query(l, r-1) << endl;
		}
	}
	
	return 0;
}
0