Language: C++

#include<bits/stdc++.h>
using namespace std;
using ll = long long;



template<class M> class SegmentTree {
    using T = M::T;
private:
    int n;
    vector<T> data;
public:
    SegmentTree(const vector<T>& a, T _def) {
        int m = a.size();
        for(n = 1; n < (int)a.size(); n <<= 1; depth++);
        deta.resize(n<<1, M::id);
        for(int i = 0; i < (int)a.size(); i++)deta[i + n] = a[i];
        for(int i = n - 1; i >= 1; i--) data[i] = M::op(data[i<<1], data[(i<<1) + 1]);
    }

    T get(int l, int r) {
        if(l == r)return M::id;
        l += n, r += n;
        vl = M::id, vr = M::id;
        while(l < r) {
            if(l & 1) {
                vl = M::op(vl, data[l]);
                l++;
            }
            if(r & 1) {
                r--;
                vr = M::op(data[r], vr);
            }
            l >>= 1, r>>=1;
        }
        return M::op(vl, vr);
    }

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

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

int main()
{
    int n, q; cin >> n >> q;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    SegmentTree<add<ll>> tree(a);

    for(int i = 0; i < q; i++) {
        ll a, b, c; cin >> a >> b >> c;
        if(a == 0) {
            tree.assign(b, c);
        } else {
            cout << tree.get(b, c) << endl;
        }
    }

}


Compiler output:
a.cc:8:15: error: need 'typename' before 'M::T' because 'M' is a dependent scope
    8 |     using T = M::T;
      |               ^
      |               typename 
a.cc:11:12: error: 'T' was not declared in this scope
   11 |     vector<T> data;
      |            ^
a.cc:11:13: error: template argument 1 is invalid
   11 |     vector<T> data;
      |             ^
a.cc:11:13: error: template argument 2 is invalid
a.cc:13:30: error: 'T' was not declared in this scope
   13 |     SegmentTree(const vector<T>& a, T _def) {
      |                              ^
a.cc:13:31: error: template argument 1 is invalid
   13 |     SegmentTree(const vector<T>& a, T _def) {
      |                               ^
a.cc:13:31: error: template argument 2 is invalid
a.cc:13:37: error: 'T' has not been declared
   13 |     SegmentTree(const vector<T>& a, T _def) {
      |                                     ^
a.cc:21:5: error: 'T' does not name a type
   21 |     T get(int l, int r) {
      |     ^
a.cc:39:28: error: 'T' has not been declared
   39 |     void assign(int index, T val) {
      |                            ^
a.cc: In constructor 'SegmentTree<M>::SegmentTree(const int&, int)':
a.cc:14:19: error: request for member 'size' in 'a', which is of non-class type 'const int'
   14 |         int m = a.size();
      |                   ^~~~
a.cc:15:31: error: request for member 'size' in 'a', which is of non-class type 'const int'
   15 |         for(n = 1; n < (int)a.size(); n <<= 1; depth++);
      |                               ^~~~
a.cc:15:46: error: expected ')' before ';' token
   15 |         for(n = 1; n < (int)a.size(); n <<= 1; depth++);
      |                                              ^
a.cc:15:12: note: to match this '('
   15 |         for(n = 1; n < (int)a.size(); n <<= 1; depth++);
      |            ^
a.cc:15:48: error: 'depth' was not declared in this scope
   15 |         for(n = 1; n < (int)a.size(); n <<= 1; depth++);
      |                                                ^~~~~
a.cc:16:9: error: 'deta' was not declared in this scope; did you mean 'data'?
   16 |         deta.resize(n<<1, M::id);
      |         ^~~~
      |         data
a.cc:17:35: error: request for member 'size' in 'a', which is of non-class type 'const int'
   17 |         for(int i = 0; i < (int)a.size(); i++)deta[i + n] = a[i];
      |                                   ^~~~
a.cc:17:62: error: invalid types 'const int[int]' for array subscript
   17 |         for(int i = 0; i < (int)a.size(); i++)deta[i + n] = a[i];
      |                                                              ^
a.cc:18:45: error: invalid types 'int[int]' for array subscript
   18 |         for(int i = n - 1; i >= 1; i--) data[i] = M::op(data[i<<1], data[(i<<1) + 1]);
      |                                             ^
a.cc:18:61: error: invalid types 'int[int]' for array subscript
   18 |         for(int i = n - 1; i >= 1; i--) data[i] = M::op(data[i<<1], data[(i<<1) + 1]);
      |                                                             ^
a.cc:18:73: error: invalid types 'int[int]' for array subscript
   18 |         for(int i = n - 1; i >= 1; i--) data[i] = M::op(data[i<<1], data[(i<<1) + 1]);
      |                                                                         ^
a.cc: In member function 'void SegmentTree<M>::assign(int, int)':
a.cc:41:13: error: invalid types 'int[int]' for array subscript
   41 |         data[index] = val;
      |             ^
a.cc:42:30: error: invalid types 'int[int]' for array subscript
   42 |         while(index>>=1) data[index] = M::op(data[index<<1], data[(index<<1) + 1]);
      |                              ^
a.cc:42:50: error: invalid types 'int[int]' for array subscript
   42 |         while(index>>=1) data[index] = M::op(data[index<<1], data[(index<<1) + 1]);
      |                                                  ^
a.cc:42:66: error: invalid types 'int[int]' for array subscript
   42 |         while(index>>=1) data[index] = M::op(data[index<<1], data[(index<<1) + 1]);
      |                                                                  ^
a.cc: In function 'int main()':
a.cc:58:32: error: no matching function for call to 'SegmentTree<add<long long int> >::SegmentTree(std::vector<long long int>&)'
   58 |     SegmentTree<add<ll>> tree(a);
      |                                ^
a.cc:13:5: note: candidate: 'SegmentTree<M>::SegmentTree(const int&, int) [with M = add<long long int>]'
   13 |     SegmentTree(const vector<T>& a, T _def) {
      |     ^~~~~~~~~~~
a.cc:13:5: note:   candidate expects 2 arguments, 1 provided
a.cc:7:25: note: candidate: 'constexpr SegmentTree<add<long long int> >::SegmentTree(const SegmentTree<add<long long int> >&)'
    7 | template<class M> class SegmentTree {
      |                         ^~~~~~~~~~~
a.cc:7:25: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'const SegmentTree<add<long long int> >&'
a.cc:7:25: note: candidate: 'constexpr SegmentTree<add<long long int> >::SegmentTree(SegmentTree<add<long long int> >&&)'
a.cc:7:25: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'SegmentTree<add<long long int> >&&'
a.cc:65:26: error: 'class SegmentTree<add<long long int> >' has no member named 'get'
   65 |             cout << tree.get(b, c) << endl;
      |                          ^~~