Language: C++

#include<bits/stdc++.h>

using namespace std;

const int backet = 333;

int N, Q;
vector< int > g[100000];
int in[100000], out[100000], ptr;

int sz[(10000 + backet - 1) / backet][10];
int convert[(10000 + backet - 1) / backet][10];
int data[100000];

void tour(int idx, int par = -1)
{
  in[idx] = ptr++;
  for(int &to : g[idx]) if(to != par) tour(to, idx);
  out[idx] = ptr;
}

void push(int k)
{
  for(int i = k * backet; i < min(N, (k + 1) * backet); i++) {
    data[i] = convert[k][data[i]];
  }
  for(int i = 0; i < 10; i++) {
    convert[k][i] = i;
    sz[k][i] = 0;
  }
  for(int i = k * backet; i < min(N, (k + 1) * backet); i++) {
    sz[k][data[i]]++;
  }
}

int main()
{
  cin >> N >> Q;
  for(int i = 1; i < N; i++) {
    int U, V;
    cin >> U >> V;
    g[U].push_back(V);
    g[V].push_back(U);
  }
  tour(0);

  int all = (N + backet - 1) / backet;
  memset(convert, -1, sizeof(convert));
  for(int i = 0; i < all; i++) {
    sz[i][0] += min(N, (i + 1) * backet) - i * backet;
    for(int j = 0; j < 10; j++) convert[i][j] = j;
  }

  while(Q--) {
    int t, s, x, y;
    cin >> t >> s >> x >> y;

    int a = in[s], b = out[s];

    if(t == 1) {
      int sum = 0;
      for(int i = 0; i < all; i++) {
        int l = i * backet, r = min(N, (i + 1) * backet);
        if(a >= r || b <= l) continue;
        if(a <= l && r <= b) {
          for(int k = 0; k <= 10; k++) {
            if(x <= convert[i][k] && convert[i][k] <= y) sum += sz[i][k];
          }
        } else {
          push(i);
          for(int j = max(a, l); j < min(b, r); j++) {
            if(x <= data[j] && data[j] <= y) sum++;
          }
        }
      }
      cout << sum << endl;
    } else {
      for(int i = 0; i < all; i++) {
        int l = i * backet, r = min(N, (i + 1) * backet);
        if(a >= r || b <= l) continue;
        if(a <= l && r <= b) {
          convert[i][x] = y;
        } else {
          push(i);
          for(int j = max(a, l); j < min(b, r); j++) {
            if(data[j] == x) {
              data[j] = y;
              --sz[i][x];
              ++sz[i][y];
            }
          }
        }
      }
    }
  }
}

Compiler output:
a.cc: In function 'void push(int)':
a.cc:25:5: error: reference to 'data' is ambiguous
   25 |     data[i] = convert[k][data[i]];
      |     ^~~~
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:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:13:5: note:                 'int data [100000]'
   13 | int data[100000];
      |     ^~~~
a.cc:25:26: error: reference to 'data' is ambiguous
   25 |     data[i] = convert[k][data[i]];
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:13:5: note:                 'int data [100000]'
   13 | int data[100000];
      |     ^~~~
a.cc:32:11: error: reference to 'data' is ambiguous
   32 |     sz[k][data[i]]++;
      |           ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:13:5: note:                 'int data [100000]'
   13 | int data[100000];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:72:21: error: reference to 'data' is ambiguous
   72 |             if(x <= data[j] && data[j] <= y) sum++;
      |                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:13:5: note:                 'int data [100000]'
   13 | int data[100000];
      |     ^~~~
a.cc:72:32: error: reference to 'data' is ambiguous
   72 |             if(x <= data[j] && data[j] <= y) sum++;
      |                                ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:13:5: note:                 'int data [100000]'
   13 | int data[100000];
      |     ^~~~
a.cc:86:16: error: reference to 'data' is ambiguous
   86 |             if(data[j] == x) {
      |                ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:13:5: note:                 'int data [100000]'
   13 | int data[100000];
      |     ^~~~
a.cc:87:15: error: reference to 'data' is ambiguous
   87 |               data[j] = y;
      |               ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:13:5: note:                 'int data [100000]'
   13 | int data[100000];
      |     ^~~~