Language: C++

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define ar array
#define endl '\n'
#define all(x) x.begin(), x.end()
#define sz(x) ((long long)x.size())

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}


void pre(){


}

struct  data{
    int l,r,i;
};  
int bit[maxs];
int n,q;

void add(int ind,int val){
    while(ind <= n){
        bit[ind] += val;
        ind += ind&-ind;
    }
}

int get(int ind){
    int sum=0;
    while(ind){
        sum += bit[ind];
        ind -= ind&-ind;
    }
    return sum;
}

void solve(){    

    cin >> n >> q;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    data AllQueries[q+1];
    for(int i=1;i<=q;i++){
        cin >> AllQueries[i].l >> AllQueries[i].r;
        AllQueries[i].i = i;
    }
    vector<int> ans(q+1,0);
    sort(AllQueries+1,AllQueries+q+1,[&](data A,data B)->bool{
        return A.r < B.r;
    });

    int ptr_query=1;
    map<int,int> prev;
    for(int i=1;i<=n;i++){
        if(prev.count(a[i])){
            add(prev[a[i]],-1);
        }
        add(i,1);

        while(ptr_query <= q and i == AllQueries[ptr_query].r){
            int l = AllQueries[ptr_query].l;
            int r = i;
            int ind = AllQueries[ptr_query].i;
            int cur_ans = get(r) - get(l-1);
            ans[ind] = cur_ans;
            ptr_query++;
        }
        prev[a[i]] = i;
    }

    for(int i=1;i<=q;i++){
        cout << ans[i] << endl;
    }

}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input00.txt","r",stdin);
    #endif
    IOS;
    pre();
    ll T = 1;
    //cin >> T;
    while(T--){
        solve();   
    }
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:81:5: error: reference to 'data' is ambiguous
   81 |     data AllQueries[q+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: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:52:9: note:                 'struct data'
   52 | struct  data{
      |         ^~~~
a.cc:83:16: error: 'AllQueries' was not declared in this scope
   83 |         cin >> AllQueries[i].l >> AllQueries[i].r;
      |                ^~~~~~~~~~
a.cc:87:10: error: 'AllQueries' was not declared in this scope
   87 |     sort(AllQueries+1,AllQueries+q+1,[&](data A,data B)->bool{
      |          ^~~~~~~~~~
a.cc:87:42: error: reference to 'data' is ambiguous
   87 |     sort(AllQueries+1,AllQueries+q+1,[&](data A,data B)->bool{
      |                                          ^~~~
/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:52:9: note:                 'struct data'
   52 | struct  data{
      |         ^~~~
a.cc:87:42: error: 'data' has not been declared
   87 |     sort(AllQueries+1,AllQueries+q+1,[&](data A,data B)->bool{
      |                                          ^~~~
a.cc:87:49: error: reference to 'data' is ambiguous
   87 |     sort(AllQueries+1,AllQueries+q+1,[&](data A,data B)->bool{
      |                                                 ^~~~
/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:52:9: note:                 'struct data'
   52 | struct  data{
      |         ^~~~
a.cc:87:49: error: 'data' has not been declared
   87 |     sort(AllQueries+1,AllQueries+q+1,[&](data A,data B)->bool{
      |                                                 ^~~~
a.cc: In lambda function:
a.cc:88:18: error: request for member 'r' in 'A', which is of non-class type 'int'
   88 |         return A.r < B.r;
      |                  ^
a.cc:88:24: error: request for member 'r' in 'B', which is of non-class type 'int'
   88 |         return A.r < B.r;
      |                        ^