Language: C++

struct segtree {
  int n;
  vector<int> d;
  segtree(int mx) {
    n = 1;
    while (n < mx) n <<= 1;
    d = vector<int>(n<<1);
  }
  int getmax(int a, int b, int i=1, int l=0, int r=-1) {
    if (r == -1) r = n;
    if (a <= l && r <= b) return d[i];
    int res = 0;
    int c = (l+r)>>1;
    if (a < c) res = max(res, getmax(a, b, i<<1, l, c));
    if (c < b) res = max(res, getmax(a, b, i<<1|1, c, r));
    return res;
  }
  void add(int i, int x) {
    i += n;
    while (i) {
      d[i] = max(d[i], x);
      i >>= 1;
    }
  }
};

//////////////////////////////////////////////

//Monoid, 1点更新(書き換え)区間取得
//要素数, 2項演算, 単位元 (, 初期データ)
//todo:1点取得も関数化する？
template<typename T>
struct SegmentTree{
    typedef function<T(T,T)> F;
    int n;    //要素数
    F f;    //2項演算
    T e;    //単位元
    vector<T> dat;
    SegmentTree(int n_,F f,T e):f(f),e(e){
        init(n_);
        build();
    }
    SegmentTree(int n_,F f,T e,vector<T>& v):f(f),e(e){
        init(n_);
        build(n_,v);
    }
    void init(int n_){
        n=1;
        while(n<n_)n<<=1;
        dat.clear();
        dat.resize(n<<1, e);
    }
    void build(int n_,const vector<T>& v){
        for(int i=0;i<n_;++i)dat[n+i]=v[i];
        build();
    }
    void build(){
        for(int i=n-1;i>=1;--i){
            dat[i] = f(dat[i<<1],dat[i<<1|1]);
        }
    }
    void update(int k,const T& x){
        dat[k+=n]=x;
        while(k>>=1){
            dat[k] = f(dat[k<<1],dat[k<<1|1]);
        }
    }
    int query(int a,int b){
        T l=e,r=e;
        for(a+=n,b+=n;a<b;a>>=1,b>>=1){
            if(a&1)l=f(l,dat[a++]);
            if(b&1)r=f(dat[--b],r);
        }
        return f(l,r);
    }
};

Compiler output:
a.cc:3:3: error: 'vector' does not name a type
    3 |   vector<int> d;
      |   ^~~~~~
a.cc: In constructor 'segtree::segtree(int)':
a.cc:7:5: error: 'd' was not declared in this scope
    7 |     d = vector<int>(n<<1);
      |     ^
a.cc:7:9: error: 'vector' was not declared in this scope
    7 |     d = vector<int>(n<<1);
      |         ^~~~~~
a.cc:7:16: error: expected primary-expression before 'int'
    7 |     d = vector<int>(n<<1);
      |                ^~~
a.cc: In member function 'int segtree::getmax(int, int, int, int, int)':
a.cc:11:34: error: 'd' was not declared in this scope
   11 |     if (a <= l && r <= b) return d[i];
      |                                  ^
a.cc:14:22: error: 'max' was not declared in this scope
   14 |     if (a < c) res = max(res, getmax(a, b, i<<1, l, c));
      |                      ^~~
a.cc:15:22: error: 'max' was not declared in this scope
   15 |     if (c < b) res = max(res, getmax(a, b, i<<1|1, c, r));
      |                      ^~~
a.cc: In member function 'void segtree::add(int, int)':
a.cc:21:7: error: 'd' was not declared in this scope
   21 |       d[i] = max(d[i], x);
      |       ^
a.cc:21:14: error: 'max' was not declared in this scope
   21 |       d[i] = max(d[i], x);
      |              ^~~
a.cc: At global scope:
a.cc:34:13: error: 'function' does not name a type; did you mean 'union'?
   34 |     typedef function<T(T,T)> F;
      |             ^~~~~~~~
      |             union
a.cc:36:5: error: 'F' does not name a type
   36 |     F f;    //2項演算
      |     ^
a.cc:38:5: error: 'vector' does not name a type
   38 |     vector<T> dat;
      |     ^~~~~~
a.cc:39:24: error: 'F' has not been declared
   39 |     SegmentTree(int n_,F f,T e):f(f),e(e){
      |                        ^
a.cc:43:24: error: 'F' has not been declared
   43 |     SegmentTree(int n_,F f,T e,vector<T>& v):f(f),e(e){
      |                        ^
a.cc:43:32: error: 'vector' has not been declared
   43 |     SegmentTree(int n_,F f,T e,vector<T>& v):f(f),e(e){
      |                                ^~~~~~
a.cc:43:38: error: expected ',' or '...' before '<' token
   43 |     SegmentTree(int n_,F f,T e,vector<T>& v):f(f),e(e){
      |                                      ^
a.cc:53:29: error: 'vector' does not name a type
   53 |     void build(int n_,const vector<T>& v){
      |                             ^~~~~~
a.cc:53:35: error: expected ',' or '...' before '<' token
   53 |     void build(int n_,const vector<T>& v){
      |                                   ^
a.cc: In constructor 'SegmentTree<T>::SegmentTree(int, int, T)':
a.cc:39:33: error: class 'SegmentTree<T>' does not have any field named 'f'
   39 |     SegmentTree(int n_,F f,T e):f(f),e(e){
      |                                 ^
a.cc: In constructor 'SegmentTree<T>::SegmentTree(int, int, T, int)':
a.cc:43:46: error: class 'SegmentTree<T>' does not have any field named 'f'
   43 |     SegmentTree(int n_,F f,T e,vector<T>& v):f(f),e(e){
      |                                              ^
a.cc:45:18: error: 'v' was not declared in this scope
   45 |         build(n_,v);
      |                  ^
a.cc: In member function 'void SegmentTree<T>::init(int)':
a.cc:50:9: error: 'dat' was not declared in this scope
   50 |         dat.clear();
      |         ^~~
a.cc: In member function 'void SegmentTree<T>::build(int, int)':
a.cc:54:30: error: 'dat' was not declared in this scope
   54 |         for(int i=0;i<n_;++i)dat[n+i]=v[i];
      |                              ^~~
a.cc:54:39: error: 'v' was not declared in this scope
   54 |         for(int i=0;i<n_;++i)dat[n+i]=v[i];
      |                                       ^
a.cc: In member function 'void SegmentTree<T>::build()':
a.cc:59:13: error: 'dat' was not declared in this scope
   59 |             dat[i] = f(dat[i<<1],dat[i<<1|1]);
      |             ^~~
a.cc:59:22: error: there are no arguments to 'f' that depend on a template parameter, so a declaration of 'f' must be available [-fpermissive]
   59 |             dat[i] = f(dat[i<<1],dat[i<<1|1]);
      |                      ^
a.cc:59:22: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc: In member function 'void SegmentTree<T>::update(int, const T&)':
a.cc:63:9: error: 'dat' was not declared in this scope
   63 |         dat[k+=n]=x;
      |         ^~~
a.cc:65:22: error: there are no arguments to 'f' that depend on a template parameter, so a declaration of 'f' must be available [-fpermissive]
   65 |             dat[k] = f(dat[k<<1],dat[k<<1|1]);
      |                      ^
a.cc: In member function 'int SegmentTree<T>::query(int, int)':
a.cc:71:26: error: 'dat' was not declared in this scope
   71 |             if(a&1)l=f(l,dat[a++]);
      |                          ^~~
a.cc:72:24: error: 'dat' was not declared in this scope
   72 |             if(b&1)r=f(dat[--b],r);
      |                        ^~~