Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
 
using namespace std;
const int maxn=500000+5;
map<int,int> mp;
int data[maxn],a[maxn],ans[4*maxn];
struct node{
    int l,r,id;
    bool operator<(node t)const{
        return r<t.r;
    }
}q[4*maxn];
 
int lowbit(int x)
{
    return x&-x;
}
 
int Get_sum(int i)
{
    int ans=0;
    while(i>0){
        ans+=data[i];
        i-=lowbit(i);
    }
    return ans;
}
 
void Update(int i,int x)
{
    while(i<maxn){
        data[i]+=x;
        i+=lowbit(i);
    }
}
 
void solve(int T)
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
    	scanf("%d",&a[i]);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].id=i;
    }
    sort(q,q+m);
    int pre=1;
    for(int i=0;i<m;i++)
    {
        for(int j=pre;j<=q[i].r;j++)
        {
            if(mp[a[j]]!=0)
                Update(mp[a[j]],-1);
                Update(j,1);
                mp[a[j]]=j;
            }
            pre=q[i].r+1;
            ans[q[i].id]=Get_sum(q[i].r)-Get_sum(q[i].l-1);
    }
    for(int i=0;i<m;i++)
        printf("%d\n",ans[i]);
    return;
}

int main(){
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


Compiler output:
a.cc: In function 'int Get_sum(int)':
a.cc:27:14: error: reference to 'data' is ambiguous
   27 |         ans+=data[i];
      |              ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:10:5: note:                 'int data [500005]'
   10 | int data[maxn],a[maxn],ans[4*maxn];
      |     ^~~~
a.cc: In function 'void Update(int, int)':
a.cc:36:9: error: reference to 'data' is ambiguous
   36 |         data[i]+=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:10:5: note:                 'int data [500005]'
   10 | int data[maxn],a[maxn],ans[4*maxn];
      |     ^~~~