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];
    }
    vector<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.begin()+1,AllQueries.end(),[&](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(){
    
    IOS;
    pre();
    ll T = 1;
    //cin >> T;
    while(T--){
        solve();   
    }
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:81:16: error: template argument 1 is invalid
   81 |     vector<data> AllQueries(q+1);
      |                ^
a.cc:81:16: error: template argument 2 is invalid
a.cc:83:26: error: invalid types 'int[int]' for array subscript
   83 |         cin >> AllQueries[i].l >> AllQueries[i].r;
      |                          ^
a.cc:83:45: error: invalid types 'int[int]' for array subscript
   83 |         cin >> AllQueries[i].l >> AllQueries[i].r;
      |                                             ^
a.cc:84:19: error: invalid types 'int[int]' for array subscript
   84 |         AllQueries[i].i = i;
      |                   ^
a.cc:87:21: error: request for member 'begin' in 'AllQueries', which is of non-class type 'int'
   87 |     sort(AllQueries.begin()+1,AllQueries.end(),[&](data A,data B)->bool{
      |                     ^~~~~
a.cc:87:42: error: request for member 'end' in 'AllQueries', which is of non-class type 'int'
   87 |     sort(AllQueries.begin()+1,AllQueries.end(),[&](data A,data B)->bool{
      |                                          ^~~
a.cc:87:52: error: reference to 'data' is ambiguous
   87 |     sort(AllQueries.begin()+1,AllQueries.end(),[&](data A,data B)->bool{
      |                                                    ^~~~
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:87:52: error: 'data' has not been declared
   87 |     sort(AllQueries.begin()+1,AllQueries.end(),[&](data A,data B)->bool{
      |                                                    ^~~~
a.cc:87:59: error: reference to 'data' is ambiguous
   87 |     sort(AllQueries.begin()+1,AllQueries.end(),[&](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:59: error: 'data' has not been declared
   87 |     sort(AllQueries.begin()+1,AllQueries.end(),[&](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;
      |                        ^
a.cc: In function 'void solve()':
a.cc:99:49: error: invalid types 'int[int]' for array subscript
   99 |         while(ptr_query <= q and i == AllQueries[ptr_query].r){
      |                                                 ^
a.cc:100:31: error: invalid types 'int[int]' for array subscript
  100 |             int l = AllQueries[ptr_query].l;
      |                               ^
a.cc:102:33: error: invalid types 'int[int]' for array subscript
  102 |             int ind = AllQueries[ptr_query].i;
      |                                 ^