Language: C++

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

using namespace std;
  
typedef long long LL;
  
const int inf=0x3f3f3f3f;
  
const int N=2e5+100;
 
const int M=1e6+100;
 
int size,n,m,ans[N],a[N];
 
int vis[M];
 
struct query
{
	int l,r,id;
	bool operator<(const query a)const
	{
		if(l/size!=a.l/size)
			return l/size<a.l/size;
		return r<a.r;
	}
}q[N];
 
int del(int pos)
{
	vis[a[pos]]--;
	if(vis[a[pos]]==0)
		return -1;
	return 0;
}
 
int add(int pos)
{
	vis[a[pos]]++;
	if(vis[a[pos]]==1)
		return 1;
	return 0;
}
 
void solve()
{
	int l=1,r=0;
	int sum=0;
	for(int i=1;i<=m;i++)
	{
		int ql=q[i].l;
		int qr=q[i].r;
		while(l<ql)
			sum+=del(l++);
		while(l>ql)
			sum+=add(--l);
		while(r<qr)
			sum+=add(++r);
		while(r>qr)
			sum+=del(r--);
		ans[q[i].id]=sum;
	}
}
 
int main()
{
//  freopen("input.txt","r",stdin);
//    ios::sync_with_stdio(false);
	scanf("%d%d",&n, &m);
	size=sqrt(n);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].id=i;
	}
    sort(q+1,q+1+m);
    solve();
    for(int i=1;i<=m;i++)
    	printf("%d\n",ans[i]);
      
    return 0;
}


Compiler output:
a.cc: In member function 'bool query::operator<(query) const':
a.cc:27:22: error: reference to 'size' is ambiguous
   27 |                 if(l/size!=a.l/size)
      |                      ^~~~
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:18:5: note:                 'int size'
   18 | int size,n,m,ans[N],a[N];
      |     ^~~~
a.cc:27:32: error: reference to 'size' is ambiguous
   27 |                 if(l/size!=a.l/size)
      |                                ^~~~
/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:18:5: note:                 'int size'
   18 | int size,n,m,ans[N],a[N];
      |     ^~~~
a.cc:28:34: error: reference to 'size' is ambiguous
   28 |                         return l/size<a.l/size;
      |                                  ^~~~
/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:18:5: note:                 'int size'
   18 | int size,n,m,ans[N],a[N];
      |     ^~~~
a.cc:28:43: error: reference to 'size' is ambiguous
   28 |                         return l/size<a.l/size;
      |                                           ^~~~
/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:18:5: note:                 'int size'
   18 | int size,n,m,ans[N],a[N];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:74:9: error: reference to 'size' is ambiguous
   74 |         size=sqrt(n);
      |         ^~~~
/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:18:5: note:                 'int size'
   18 | int size,n,m,ans[N],a[N];
      |     ^~~~