Language: C++


#include <vector>
using namespace std;

//Base class for Segment Trees
template <class T> 
class segtree_base
{
protected:
	vector<T> vec;
	T def;
	virtual T query_raw(int l_, int r_, int a_, int b_, int k_) = 0;
public:
	segtree_base(size_t size_, const T& def_ = T()) : def(def_)
	{
		size_t s = 1; 
		while (s < size_)s *= 2;
		vec.resize(s, def);
	}
	T query(int left, int right)
	{
		return query_raw(left, right, 0, vec.size(), 0);
	}
	virtual ~segtree_base() {}
};

//Range Minimum Tree
template <class T>
class rmq_tree : public segtree_base<T>
{
public:
	rmq_tree(size_t size_, const T& def) : segtree_base(size_, def)
	{}
	void update(int index,int val)
	{
		index += (vec.size() - 1);
		vec[index] = val;
		while (index > 0)
		{
			index = (index - 1) / 2;
			vec[index] = min(vec[index * 2 + 1], vec[index * 2 + 2]);
		}
	}
private:
	T query_raw(int l_, int r_, int a_, int b_, int k_)override
	{
		if (a_ <= l_ && r_ <= b_)
		{
			return vec[k];
		}
		if (b_ <= l_ || r_ <= a_)
		{
			return def;
		}
		int m = (l_ + r_) / 2;
		return min(
			query_raw(l_, m, a_, b_, k + k + 1), 
			query_raw(m, r_, a_, b_, k + k + 2));
	}
};

#include <iostream>
#include <climits>

int main()
{
	int n, q;
	cin >> n >> q;
	rmq_tree<int>rmq(n, INT_MAX);
	for (int i = 0; i < q; ++i)
	{
		int com, x, y;
		cin >> com >> x >> y;
		if (com)
		{
			cout << rmq.query(x, y + 1) << endl;
		}
		else
		{
			rmq.update(x, y);
		}
	}
	return 0;
}

Compiler output:
a.cc: In constructor 'rmq_tree<T>::rmq_tree(size_t, const T&)':
a.cc:32:48: error: class 'rmq_tree<T>' does not have any field named 'segtree_base'
   32 |         rmq_tree(size_t size_, const T& def) : segtree_base(size_, def)
      |                                                ^~~~~~~~~~~~
a.cc: In member function 'void rmq_tree<T>::update(int, int)':
a.cc:36:27: error: 'vec' was not declared in this scope
   36 |                 index += (vec.size() - 1);
      |                           ^~~
a.cc: In member function 'T rmq_tree<T>::query_raw(int, int, int, int, int)':
a.cc:49:32: error: 'vec' was not declared in this scope
   49 |                         return vec[k];
      |                                ^~~
a.cc:49:36: error: 'k' was not declared in this scope
   49 |                         return vec[k];
      |                                    ^
a.cc:53:32: error: 'def' was not declared in this scope
   53 |                         return def;
      |                                ^~~
a.cc:57:50: error: 'k' was not declared in this scope
   57 |                         query_raw(l_, m, a_, b_, k + k + 1),
      |                                                  ^
a.cc: In instantiation of 'rmq_tree<T>::rmq_tree(size_t, const T&) [with T = int; size_t = long unsigned int]':
a.cc:69:29:   required from here
   69 |         rmq_tree<int>rmq(n, INT_MAX);
      |                                    ^
a.cc:32:71: error: no matching function for call to 'segtree_base<int>::segtree_base()'
   32 |         rmq_tree(size_t size_, const T& def) : segtree_base(size_, def)
      |                                                                       ^
a.cc:14:9: note: candidate: 'segtree_base<T>::segtree_base(size_t, const T&) [with T = int; size_t = long unsigned int]'
   14 |         segtree_base(size_t size_, const T& def_ = T()) : def(def_)
      |         ^~~~~~~~~~~~
a.cc:14:9: note:   candidate expects 2 arguments, 0 provided
a.cc:7:7: note: candidate: 'segtree_base<int>::segtree_base(const segtree_base<int>&)'
    7 | class segtree_base
      |       ^~~~~~~~~~~~
a.cc:7:7: note:   candidate expects 1 argument, 0 provided