結果
| 問題 | No.789 範囲の合計 | 
| コンテスト | |
| ユーザー |  AC2K | 
| 提出日時 | 2023-03-27 20:08:57 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 3,971 bytes | 
| コンパイル時間 | 3,219 ms | 
| コンパイル使用メモリ | 248,492 KB | 
| 実行使用メモリ | 32,000 KB | 
| 最終ジャッジ日時 | 2024-09-19 15:17:56 | 
| 合計ジャッジ時間 | 4,855 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 13 RE * 2 | 
ソースコード
#line 1 "test/yuki/No-789.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/789"
#line 2 "src/template.hpp"
#include<bits/stdc++.h>
using namespace std;
#define rep(i, N)  for(int i=0;i<(N);i++)
#define all(x) (x).begin(),(x).end()
#define popcount(x) __builtin_popcount(x)
using i128=__int128_t;
using ll = long long;
using ld = long double;
using graph = vector<vector<int>>;
using P = pair<int, int>;
constexpr int inf = 1e9;
constexpr ll infl = 1e18;
constexpr ld eps = 1e-6;
const long double pi = acos(-1);
constexpr uint64_t MOD = 1e9 + 7;
constexpr uint64_t MOD2 = 998244353;
constexpr int dx[] = { 1,0,-1,0 };
constexpr int dy[] = { 0,1,0,-1 };
template<class T>inline void chmax(T&x,T y){if(x<y)x=y;}
template<class T>inline void chmin(T&x,T y){if(x>y)x=y;}
#line 1 "src/data-structure/dynamic_segtree.hpp"
/// @brief Dynamic Segment Tree(動的セグメント木)
/// @tparam S 要素の型
/// @tparam op 二項演算
/// @tparam e 単位元
/// @docs docs/data-structure/dynamic_segtree.md
template<class S, S(*op)(S, S), S(*e)()>
class dynamic_segtree {
public:
	dynamic_segtree(const size_t& n) :n(n), root(nullptr) {}
private:
	struct node {
		S val;
		node* left;
		node* right;
		node(const S& v) :val(v), left(nullptr), right(nullptr) {}
	};
	node* root;
	size_t n;
public:
	void update(const size_t& p, const S& x) {
		assert(0 <= p && p < n);
		internal_update(root, 0, n, p, x);
	}
	void add(const size_t& p, const S& x) {
		assert(0 <= p && p < n);
		internal_add(root, 0, n, p, x);
	}
	S operator[](const size_t& p) {
		assert(0 <= p && p < n);
		return internal_access(root, 0, n, p);
	}
	S prod(const size_t& l, const size_t& r) {
		assert(0 <= l && l <= r && r <= n);
		if (l == r) {
			return e();
		}
		if (l == 0 && r == n) {
			return root->val;
		}
		return internal_prod(root, 0, n, l, r);
	}
private:
	void internal_update(node*& p, const size_t& l, const size_t& r, const  size_t& idx, const S& new_val) {
		if (p == nullptr) {
			p = new node(e());
		}
		if (r - l == 1) {
			p->val = new_val;
			return;
		}
		size_t mid = (l + r) >> 1;
		if (idx < mid) internal_update(p->left, l, mid, idx, new_val);
		else internal_update(p->right, mid, r, idx, new_val);
		p->val = e();
		if (p->left != nullptr) p->val = op(p->left->val, p->val);
		if (p->right != nullptr) p->val = op(p->val, p->right->val);
	}
	void internal_add(node*& p, const size_t& l, const size_t& r, const  size_t& idx, const S& new_val) {
		if (p == nullptr) {
			p = new node(e());
		}
		if (r - l == 1) {
			p->val = op(p->val, new_val);;
			return;
		}
		size_t mid = (l + r) >> 1;
		if (idx < mid) internal_add(p->left, l, mid, idx, new_val);
		else internal_add(p->right, mid, r, idx, new_val);
		p->val = e();
		if (p->left != nullptr) p->val = op(p->left->val, p->val);
		if (p->right != nullptr) p->val = op(p->val, p->right->val);
	}
	S internal_access(node*& p, const size_t& l, const size_t& r, const  size_t& idx) {
		if (p == nullptr) {
			return e();
		}
		if (r - l == 1) {
			return p->val;
		}
		size_t mid = (l + r) >> 1;
		if (idx < mid) return internal_access(p->left, l, mid, idx);
		else return internal_access(p->right, mid, r, idx);
	}
	S internal_prod(node*& p, const size_t& l, const size_t& r, const size_t& L, const size_t& R) {
		if (p == nullptr || r <= L || R <= l) {
			return e();
		}
		if (L <= l && r <= R) {
			return p->val;
		}
		size_t mid = (l + r) >> 1;
		return op(internal_prod(p->left, l, mid, L, R), internal_prod(p->right, mid, r, L, R));
	}
};
#line 5 "test/yuki/No-789.test.cpp"
ll op(ll x, ll y) { return x + y; }
ll e() { return 0; }
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    dynamic_segtree<ll, op, e> sg(inf + 1);
    int n;
    cin >> n;
    ll s = 0;
    while (n--) {
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 0) {
            sg.add(a, b);
        } else {
            s += sg.prod(a, b + 1);
        }
    }
    cout << s << '\n';
}
            
            
            
        