Language: C++

#include<bits/stdc++.h>
using namespace std;
int lastoc[6000001];
int tree[6000000];
struct data{
	int i,j,k;
};
void  update(int i,int up,int n)
{
	while(i<=n)
	{
		tree[i]+=up;
		i=i+(i&-i);
	}
}
int que(int i)
{
	int ans=0;
	while(i>0)
	{
		ans+=tree[i];
		i=i-(i&-i);
	}
	return ans;
}
bool com(data& a,data& b)
{
	return a.j<b.j;
}
int main()
{
	int n;
	scanf("%d",&n);
		int q;
		scanf("%d",&q);
	int a[n+1];
	for(int i=1;i<=n;i++)
	cin>>a[i];


	data query[q];
	for(int i=0;i<q;i++)
	{
			scanf("%d%d",&query[i].i,&query[i].j);
		query[i].k=i;
	}
	sort(query,query+q,com);
	int x=0;
	int res[q]={0};
//	memset(lastoc,0,sizeof(lastoc));
	for(int i=1;i<=n;i++)
	{
		if(lastoc[a[i]]!=0)
		update(lastoc[a[i]],-1,n);
		update(i,1,n);
	    lastoc[a[i]]=i;
		while(x<q&&query[x].j==i)
		{
			res[query[x].k]=que(query[x].j)-que(query[x].i-1);
			x++;
	
		}
	}
	for(int i=0;i<q;i++)
	printf("%d\n",res[i]);
}

Compiler output:
a.cc:26:10: error: reference to 'data' is ambiguous
   26 | bool com(data& a,data& b)
      |          ^~~~
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:5:8: note:                 'struct data'
    5 | struct data{
      |        ^~~~
a.cc:26:16: error: 'a' was not declared in this scope
   26 | bool com(data& a,data& b)
      |                ^
a.cc:26:18: error: reference to 'data' is ambiguous
   26 | bool com(data& a,data& b)
      |                  ^~~~
/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:5:8: note:                 'struct data'
    5 | struct data{
      |        ^~~~
a.cc:26:24: error: 'b' was not declared in this scope
   26 | bool com(data& a,data& b)
      |                        ^
a.cc:26:25: error: expression list treated as compound expression in initializer [-fpermissive]
   26 | bool com(data& a,data& b)
      |                         ^
a.cc: In function 'int main()':
a.cc:41:9: error: reference to 'data' is ambiguous
   41 |         data query[q];
      |         ^~~~
/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:5:8: note:                 'struct data'
    5 | struct data{
      |        ^~~~
a.cc:44:39: error: 'query' was not declared in this scope; did you mean 'que'?
   44 |                         scanf("%d%d",&query[i].i,&query[i].j);
      |                                       ^~~~~
      |                                       que
a.cc:47:14: error: 'query' was not declared in this scope; did you mean 'que'?
   47 |         sort(query,query+q,com);
      |              ^~~~~
      |              que