Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define re() pop_back()
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(a) a.begin(),a.end()
#define msort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

const int N= 5e5+ 4;
int data[N];
vector<int> last(N),c(N);

void update(int i,int val){
    while(i<N){
        data[i]+=val;
        i+=i&-i;
    }
}

int sum(int i){
    int sum=0;
    while(i){
        sum+=data[i];
        i-=i&-i;
    }
    return sum;
}

int rangesum(int l,int r) {
    return sum(r)-sum(l-1);
}


void sol()
{
    int n,q;
    cin>>n>>q;
    // cout<<1<<endl;
    // return;
    for (int i = 0; i < n; i++)
    {
        cin>>c[i];
    }
    
    for (int i = 0; i < n; i++)
    {
        last[i]=-1;
    }
    
    int ans[N];
    vector<int> qi[N],qs[N];
    for (int i = 0; i <q; i++)
    {
        int x,y;
        cin>>x>>y;
        qi[y].eb(i);
        qs[y].eb(x);

    }
    
    for (int i = 0; i < n; i++)
    {
        if(last[c[i]]!=-1) {
            update(last[c[i]],-1);
        }
        update(i,1);
        last[c[i]]=i;
        for (int j = 0; j< qs[i].size(); j++)
        {
            ans[qi[i][j]]=rangesum(qs[i][j],i);
        }
        
    }
    
    for (int i = 0; i < n; i++)
    {
        cout<<ans[i]<<endl;
    }
}

int main()
{
    IOS;
    ll t=1;// cin>>t;
    while (t--)
    {
        // cout<<1<<endl;
        sol();
    }
}

Compiler output:
a.cc: In function 'void update(int, int)':
a.cc:27:9: error: reference to 'data' is ambiguous
   27 |         data[i]+=val;
      |         ^~~~
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:22:5: note:                 'int data [500004]'
   22 | int data[N];
      |     ^~~~
a.cc: In function 'int sum(int)':
a.cc:35:14: error: reference to 'data' is ambiguous
   35 |         sum+=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:22:5: note:                 'int data [500004]'
   22 | int data[N];
      |     ^~~~