Language: C++

#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e8)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 1e6+5;
ll st[MAXN],ed[MAXN],belong[MAXN],t[MAXN],size[MAXN];
vector<ll>a;
void init(int n)
{
	int num = sqrt(n);
	for(int i=1;i<=num;i++){
		st[i] = n/num*(i-1)+1;
		ed[i] = n/num*i;
	}
	ed[num] = n;
	for(int i=1;i<=num;i++){
		for(int j=st[i];j<=ed[i];j++){
			belong[j] = i;
			t[j] = a[j];
		}
		sort(t+st[i],t+ed[i]+1);
		size[i] = ed[i]-st[i]+1;
	}
}
ll get(int l,int r){
	ll res = 0;
	int x = belong[l],y = belong[r];
	if(x == y){
		for(int i=l;i<=r;i++){
			if(a[i] > r)res++;
		}
		return res;
	}
	for(int i=l;i<=ed[x];i++)if(a[i]>r)res++;
	for(int i=st[y];i<=r;i++)if(a[i]>r)res++;
	for(int i=x+1;i<y;i++){
		int p = ub(t+st[i],t+ed[i]+1,r)-t;
		p-=st[i];
		res+=size[i]-p;
		//cout<<size[i]<<" "<<p<<'\n';
	}
	return res;
}
int main()
{
	owo
	int n,q;
	cin>>n>>q;
	a.resize(n+1);
	vector<ll>occ(n+1,n+1);
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=n;i>0;i--){
		int tmp = a[i];
		a[i] = occ[a[i]];
		occ[tmp] = i;
	}
///	for(int i=1;i<=n;i++)cout<<a[i]<<" ";
	//cout<<'\n';
	init(n);
	while(q--)
	{
		int l,r;
		cin>>l>>r;
		cout<<get(l,r)<<'\n';
		
	}
}



Compiler output:
a.cc: In function 'void init(int)':
a.cc:41:17: error: reference to 'size' is ambiguous
   41 |                 size[i] = ed[i]-st[i]+1;
      |                 ^~~~
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:2:
/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:25:43: note:                 'll size [1000005]'
   25 | ll st[MAXN],ed[MAXN],belong[MAXN],t[MAXN],size[MAXN];
      |                                           ^~~~
a.cc: In function 'll get(int, int)':
a.cc:58:22: error: reference to 'size' is ambiguous
   58 |                 res+=size[i]-p;
      |                      ^~~~
/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:25:43: note:                 'll size [1000005]'
   25 | ll st[MAXN],ed[MAXN],belong[MAXN],t[MAXN],size[MAXN];
      |                                           ^~~~