Language: C++

#include<bits/stdc++.h>

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif

const int N = 500005;
int ara[N+5];
int cnt[N + 5];
struct data
{
    int l,r,id;
};
data Q[N+5];
int answer[N+5];
int sq;
bool cmp(data A,data B)
{
    if(A.l/sq!=B.l/sq)return A.l/sq < B.l/sq;
    return A.r<B.r;
}
int value;
int add(int pos)
{
    cnt[ara[pos]]++;
    if(cnt[ara[pos]] == 1)value++;
}
int remove(int pos)
{
    cnt[ara[pos]]--;
    if(cnt[ara[pos]] == 0)value--;
}

int main()
{
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;
    int q;
    scanf("%d",&n);
    scanf("%d",&q);
    sq = sqrt(n);
    for(int i = 0;i<n;i++)scanf("%d",&ara[i]);

    for(int i = 0;i<q;i++){
        int l,r;
        scanf("%d %d",&l,&r);
        Q[i].l=l-1;
        Q[i].r=r-1;
        Q[i].id=i;
    }
    sort(Q,Q+q,cmp);

    int mol = 0;
    int mor = -1;
    for(int i = 0;i<q;i++){
        int l = Q[i].l;
        int r = Q[i].r;

        while(mor < r){
            mor++;
            add(mor);
        }
        while(mor > r){
            remove(mor);
            mor--;
        }
        while(mol < l){
            remove(mol);
            mol++;
        }

        while(mol>l){
            mol--;
            add(mol);
        }

        answer[Q[i].id]=value;
    }

    for(int i = 0;i<q;i++){
        printf("%d\n",answer[i]);
    }

    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}


Compiler output:
a.cc:62:1: error: reference to 'data' is ambiguous
   62 | data Q[N+5];
      | ^~~~
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:58:8: note:                 'struct data'
   58 | struct data
      |        ^~~~
a.cc:65:10: error: reference to 'data' is ambiguous
   65 | bool cmp(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:58:8: note:                 'struct data'
   58 | struct data
      |        ^~~~
a.cc:65:17: error: reference to 'data' is ambiguous
   65 | bool cmp(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:58:8: note:                 'struct data'
   58 | struct data
      |        ^~~~
a.cc:65:23: error: expression list treated as compound expression in initializer [-fpermissive]
   65 | bool cmp(data A,data B)
      |                       ^
a.cc: In function 'int add(int)':
a.cc:75:1: warning: no return statement in function returning non-void [-Wreturn-type]
   75 | }
      | ^
a.cc: In function 'int remove(int)':
a.cc:80:1: warning: no return statement in function returning non-void [-Wreturn-type]
   80 | }
      | ^
a.cc: In function 'int main()':
a.cc:99:9: error: 'Q' was not declared in this scope
   99 |         Q[i].l=l-1;
      |         ^
a.cc:103:10: error: 'Q' was not declared in this scope
  103 |     sort(Q,Q+q,cmp);
      |          ^