Language: C++

#include <bits/stdc++.h>
#define int long long
using namespace std;

int size;
vector<int> val;
vector<int> lazy;
vector<int> width;

void lazy_propagate(int p) {
    if (lazy[p] > 0) {
        val[p] += lazy[p] * width[p];
        if (p < size-1) {
            lazy[p*2+1] += lazy[p];
            lazy[p*2+2] += lazy[p];
        }
        lazy[p] = 0;
    }
}

void add(int wishl, int wishr, int watchl, int watchr, int k, int x) {
    if (wishr <= watchl || watchr <= wishl) {
        lazy_propagate(k);
        return;
    }
    if (wishl <= watchl && watchr <= wishr) {
        lazy[k] += x;
        lazy_propagate(k);
        return;
    }
    int mid = (watchl+watchr)/2;
    lazy_propagate(k);
    add(wishl, wishr, watchl, mid, k*2+1, x);
    add(wishl, wishr, mid, watchr, k*2+2, x);
    val[k] = val[k*2+1] + val[k*2+2];
}
void add(int wishl, int wishr, int x) {
    add(wishl, wishr, 0, size, 0, x);
}

int getsum(int wishl, int wishr, int watchl, int watchr, int k) {
    if (wishr <= watchl || watchr <= wishl) {
        return 0;
    }
    if (wishl <= watchl && watchr <= wishr) {
        lazy_propagate(k);
        return val[k];
    }
    int mid = (watchl+watchr)/2;
    lazy_propagate(k);
    int sl = getsum(wishl, wishr, watchl, mid, k*2+1);
    int sr = getsum(wishl, wishr, mid, watchr, k*2+2);
    return sl + sr;
}
int getsum(int wishl, int wishr) {
    return getsum(wishl, wishr, 0, size, 0);
}

int main() {
    int n, q;
    cin >> n >> q;
    size = 1;
    while (size < n) size <<= 1;
    val = vector<int>(size*2, 0);
    lazy = vector<int>(size*2, 0);
    width = vector<int>(size*2, 1);

    for (int i = size-2; i >= 0; i--) {
        width[i] = width[i*2+1] + width[i*2+2];
    }

    while (q--) {
        int type, l, r;
        cin >> type >> l >> r;
        if(type == 0) {
            int x;
            cin >> x;
            add(l-1, r, x);
        } else {
            cout << getsum(l-1, r) << endl;
        }
    }
    return 0;
}

Compiler output:
a.cc: In function 'void lazy_propagate(long long int)':
a.cc:13:17: error: reference to 'size' is ambiguous
   13 |         if (p < size-1) {
      |                 ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~
a.cc: In function 'void add(long long int, long long int, long long int)':
a.cc:38:26: error: reference to 'size' is ambiguous
   38 |     add(wishl, wishr, 0, size, 0, x);
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~
a.cc: In function 'long long int getsum(long long int, long long int)':
a.cc:56:36: error: reference to 'size' is ambiguous
   56 |     return getsum(wishl, wishr, 0, size, 0);
      |                                    ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~
At global scope:
cc1plus: error: '::main' must return 'int'
a.cc: In function 'int main()':
a.cc:62:5: error: reference to 'size' is ambiguous
   62 |     size = 1;
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~
a.cc:63:12: error: reference to 'size' is ambiguous
   63 |     while (size < n) size <<= 1;
      |            ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~
a.cc:63:22: error: reference to 'size' is ambiguous
   63 |     while (size < n) size <<= 1;
      |                      ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~
a.cc:64:22: error: expected primary-expression before '(' token
   64 |     val = vector<int>(size*2, 0);
      |                      ^
a.cc:64:23: error: reference to 'size' is ambiguous
   64 |     val = vector<int>(size*2, 0);
      |                       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~
a.cc:65:23: error: expected primary-expression before '(' token
   65 |     lazy = vector<int>(size*2, 0);
      |                       ^
a.cc:65:24: error: reference to 'size' is ambiguous
   65 |     lazy = vector<int>(size*2, 0);
      |                        ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~
a.cc:66:24: error: expected primary-expression before '(' token
   66 |     width = vector<int>(size*2, 1);
      |                        ^
a.cc:66:25: error: reference to 'size' is ambiguous
   66 |     width = vector<int>(size*2, 1);
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~
a.cc:68:18: error: reference to 'size' is ambiguous
   68 |     for (int i = size-2; i >= 0; i--) {
      |                  ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:5: note:                 'long long int size'
    5 | int size;
      |     ^~~~