結果

問題 No.789 範囲の合計
ユーザー manjuuu_onsenmanjuuu_onsen
提出日時 2021-09-14 01:13:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 795 ms / 1,000 ms
コード長 1,495 bytes
コンパイル時間 2,534 ms
コンパイル使用メモリ 189,236 KB
実行使用メモリ 45,656 KB
最終ジャッジ日時 2023-09-08 09:59:22
合計ジャッジ時間 10,141 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 732 ms
42,112 KB
testcase_03 AC 175 ms
4,376 KB
testcase_04 AC 795 ms
42,848 KB
testcase_05 AC 657 ms
42,044 KB
testcase_06 AC 731 ms
41,988 KB
testcase_07 AC 330 ms
4,380 KB
testcase_08 AC 727 ms
45,656 KB
testcase_09 AC 660 ms
42,680 KB
testcase_10 AC 531 ms
25,292 KB
testcase_11 AC 619 ms
42,132 KB
testcase_12 AC 615 ms
42,136 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<int,int>;

template<class M> class SegmentTree { public: using T = typename M::value_type;
private:
	int m, n;
	unordered_map<int, T> data;
	
	T modify(int node) {
		if(data.count(node)) return data[node];
		else return M::id();
	}

	T rec(int l, int r, int node, int node_l, int node_r) {
		if(node_r <= l || node_l >= r)return M::id();
		if(node_l >= l && node_r <= r)return modify(node);
		int mid = (node_l + node_r)>>1;
		return M::op( rec(l, r, node * 2, node_l, mid), rec(l, r, node * 2 + 1, mid, node_r) );
	}

public:
	SegmentTree() = default;
	SegmentTree(int N) {
		m = N;
		for(n = 1; n < N; n <<= 1);
	}

	T prod(int l, int r) {return rec(l, r, 1, 0, n);}
	T get (int i){ return modify(i + n); }
	T all_prod() {return modify(1);}

	void set(int index, T val) {
		index += n;
		data[index] = val;
		while(index != 1){
			index >>= 1;
			data[index] = M::op( modify(index<<1), modify((index<<1) + 1));
		}
	}
 
};

template<class T> class RSQ { public: using value_type = T;
	static T op(T l, T r){ return l + r; }
	static T id(){return 0;}
};

int main() {
	int Q; cin >> Q;
	SegmentTree<RSQ<ll>> seg(1'000'000'001);
	ll ans = 0;
	for(int i = 0; i < Q; i++) {
		int t, a, b; cin >> t >> a >> b;
		if(t == 0) seg.set(a, seg.get(a) + b);
		else {
			ans += seg.prod(a, b + 1);
		}
	}

	cout << ans << endl;

}
0