Language: C++


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

//??????????????°??¨
//less???greater???Comp?????\?????????
//???????§??????????operator()???????????????????????§???OK
template<typename T, typename Comp>
class RMQ {
private:
	const T DEF;//??????????????????(min??§???INF???sum??§???0??????)
	vector<T> seg;//????????????
	int width;//?????°??¨??????(???????????§????????§????????????)
	T query_raw(int a, int b, int k, int l, int r)const {
		if (a >= r || b <= l)return DEF;
		if (a <= l && r <= b)return seg[k];
		return Comp(
			query_raw(a, b, 2 * k + 1, l, (l + r) / 2),
			query_raw(a, b, 2 * k + 2, (l + r) / 2, r));
	}
public:
	//?????????n?????????????????????def????????°??¨?????????
	RMQ(int n, T def) :DEF(def) {
		width = 1;
		while (width < n)width *= 2;
		seg.assign(width * 2 - 1, DEF);
	}
	//??????[a,b)????????¨???????????????????????????
	T query(int a, int b)const { return query_raw(a, b, 0, 0, width); }
	//x?????????????´????k?????´??°??????
	void update(int k, T x) {
		k += width - 1;
		seg[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;
			seg[k] = Comp(seg[2 * k + 1], seg[2 * k + 2]);
		}
	}
	//???????????¨???????????????
	void init(const vector<T>& vec) {
		assert(vec.size() >= width);
		for (int i = 0; i < width; ++i)
			seg[i + width - 1] = vec[i];
		for (int k = width = 2; k >= 0; --k)
			seg[k] = Comp(seg[2 * k + 1], seg[2 * k + 2]);
	}
};

template <class T>
struct sum {
	bool operator()(const T&x, const T&y)const {
		return x + y;
	}
};

int main(void)
{
	int N, Q;
	cin >> N >> Q;
	RMQ<int, sum<int>>tree(N, 0);
	for (int i = 0; i < Q; ++i) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com) {
			cout << tree.query(x - 1, y) << endl;
		}
		else {
			tree.update(x - 1, tree.query(x - 1, x) + y);
		}
	}
	return 0;
}

Compiler output:
a.cc: In instantiation of 'void RMQ<T, Comp>::update(int, T) [with T = int; Comp = sum<int>]':
a.cc:93:15:   required from here
   93 |                         tree.update(x - 1, tree.query(x - 1, x) + y);
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:61:34: error: no matching function for call to 'sum<int>::sum(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   61 |                         seg[k] = Comp(seg[2 * k + 1], seg[2 * k + 2]);
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:75:8: note: candidate: 'constexpr sum<int>::sum()'
   75 | struct sum {
      |        ^~~
a.cc:75:8: note:   candidate expects 0 arguments, 2 provided
a.cc:75:8: note: candidate: 'constexpr sum<int>::sum(const sum<int>&)'
a.cc:75:8: note:   candidate expects 1 argument, 2 provided
a.cc:75:8: note: candidate: 'constexpr sum<int>::sum(sum<int>&&)'
a.cc:75:8: note:   candidate expects 1 argument, 2 provided
a.cc: In instantiation of 'T RMQ<T, Comp>::query_raw(int, int, int, int, int) const [with T = int; Comp = sum<int>]':
a.cc:54:38:   required from 'T RMQ<T, Comp>::query(int, int) const [with T = int; Comp = sum<int>]'
   54 |         T query(int a, int b)const { return query_raw(a, b, 0, 0, width); }
      |                                             ^~~~~~~~~
a.cc:90:22:   required from here
   90 |                         cout << tree.query(x - 1, y) << endl;
      |                                 ~~~~~~~~~~^~~~~~~~~~
a.cc:42:24: error: no matching function for call to 'sum<int>::sum(int, int)'
   42 |                 return Comp(
      |                        ^~~~~
   43 |                         query_raw(a, b, 2 * k + 1, l, (l + r) / 2),
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   44 |                         query_raw(a, b, 2 * k + 2, (l + r) / 2, r));
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:75:8: note: candidate: 'constexpr sum<int>::sum()'
   75 | struct sum {
      |        ^~~
a.cc:75:8: note:   candidate expects 0 arguments, 2 provided
a.cc:75:8: note: candidate: 'constexpr sum<int>::sum(const sum<int>&)'
a.cc:75:8: note:   candidate expects 1 argument, 2 provided
a.cc:75:8: note: candidate: 'constexpr sum<int>::sum(sum<int>&&)'
a.cc:75:8: note:   candidate expects 1 argument, 2 provided