Language: C++

/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}


const int MAX = 5e5+5;

struct data
{
    int l,r,idx;
};
int BLOCK_SIZE;
bool cmp(data a,data b)
{
    if(a.l/BLOCK_SIZE != b.l/BLOCK_SIZE)
        return a.l/BLOCK_SIZE < b.l/BLOCK_SIZE;
    else if((a.l/BLOCK_SIZE)&1)
        return a.r < b.r;
    return a.r > b.r;
}

data Q[MAX];
int a[MAX] , ans[MAX] , mp[MAX];
int cnt;

void add(int x)
{
    if(!mp[x])
        cnt++;
    mp[x]++;
}
void del(int x)
{
    mp[x]--;
    if(!mp[x])
        cnt--;
}
void MO(int n,int q)
{
    BLOCK_SIZE = sqrt(n);

    sort(Q,Q+q,cmp);

    int st = 0 , en = -1;
    cnt = 0;

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

        while(st > l)
        {
            st--;
            add(a[st]);
        }
        while(st < l)
        {
            del(a[st]);
            st++;
        }
        while(en < r)
        {
            en++;
            add(a[en]);

        }
        while(en > r)
        {
            del(a[en]);
            en--;
        }

        ans[idx] = cnt;
    }

    for(int i=0;i<q;i++)
       cout<<ans[i]<<"\n";
}
int main()
{
    int t,cas=1,q;

        int n;

       cin>>n>>q;
        for(int i=0;i<n;i++)
           cin>>a[i];

        for(int i=0;i<q;i++)
        {
            cin>>Q[i].l>>Q[i].r;
            Q[i].idx = i;
        }

       // printf("Case %d:\n",cas++);
        MO(n,q);



}




Compiler output:
a.cc:55:10: error: reference to 'data' is ambiguous
   55 | bool cmp(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:7:
/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:50:8: note:                 'struct data'
   50 | struct data
      |        ^~~~
a.cc:55:17: error: reference to 'data' is ambiguous
   55 | 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:50:8: note:                 'struct data'
   50 | struct data
      |        ^~~~
a.cc:55:23: error: expression list treated as compound expression in initializer [-fpermissive]
   55 | bool cmp(data a,data b)
      |                       ^
a.cc:64:1: error: reference to 'data' is ambiguous
   64 | data Q[MAX];
      | ^~~~
/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:50:8: note:                 'struct data'
   50 | struct data
      |        ^~~~
a.cc: In function 'void MO(int, int)':
a.cc:84:10: error: 'Q' was not declared in this scope
   84 |     sort(Q,Q+q,cmp);
      |          ^
a.cc:103:20: error: 'r' was not declared in this scope
  103 |         while(en < r)
      |                    ^
a.cc:109:20: error: 'r' was not declared in this scope
  109 |         while(en > r)
      |                    ^
a.cc:115:13: error: 'idx' was not declared in this scope
  115 |         ans[idx] = cnt;
      |             ^~~
a.cc: In function 'int main()':
a.cc:133:18: error: 'Q' was not declared in this scope
  133 |             cin>>Q[i].l>>Q[i].r;
      |                  ^