Language: C++

#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 5e5 + 10 ;
const ll INF = 1e18 + 10 ;
int block = 0 ;
struct Q{
    int L , R , idx;
    // bool operator<(const Q &c){
    //     if ( L / block != c.L / block ){
    //         return L / block < c.L / block ;
    //     }
    //     return R < c.R ;
    // }
};
// bool compare(Q &x , Q &y){
//     if ( x.L / block != y.L / block ){
//         return x.L / block < y.L / block ;
//     }
//     return x.R < y.R ;
// }
// bool compare(Q &x , Q &y){
//     return make_pair(x.L / block, x.R) < make_pair(y.L / block, y.R) ;
// }
bool compare(Q &x , Q &y){
    if ( x.L / block != y.L / block ) {
        return x.L / block < y.L / block ;
    }
    if ( (x.L / block) & 1 ){
        return x.R < y.R ;
    }
    return x.R > y.R ;
}
signed main(){
    fastio
    int n , t ;
    cin >> n >> t ;
    block = (int)sqrt(n + 0.0) + 1 ;
    vector<int> v(n) ;
    // int v[n] ;
    for(int i = 0; i < n; i++){
        cin >> v[i] ;
    }
    debug() << imie(range(v, v + n)) ;
    vector<Q> q(t) ;
    // Q q[t] ;
    for(int i = 0; i < t; i++){
        cin >> q[i].L >> q[i].R ;
        q[i].L-- , q[i].R--; 
        q[i].idx = i ;
    }
    sort(q.begin(), q.end(), compare) ;
    vector<int> mp(N) ;
    // int mp[N] = {0} ;
    // memset(mp, 0, sizeof mp); 
    mp[v[0]]++;
    int answer = 1;
    int curL = 0, curR = 0 ;
    vector<int> ans(t) ;
    for(int i = 0; i < t; i++){
        int L = q[i].L , R = q[i].R , idx = q[i].idx;
        while(curL > L){
            curL--;
            int &x = v[curL] ;
            mp[x]++;
            if ( mp[x] == 1 ) answer++;
        }
        while(curR < R){
            curR++;
            int &x = v[curR] ;
            mp[x]++;
            if ( mp[x] == 1 ) answer++;
        }
        while(curL < L){
            int &x = v[curL] ;
            if ( mp[x] > 0 ){
                mp[x]-- ;
                if ( mp[x] == 0 ) answer-- ;
            }
            curL++;
        }
        while(curR > R){
            int &x = v[curR] ;
            if ( mp[x] > 0 ){
                mp[x]-- ;
                if ( mp[x] == 0 ) answer-- ;
            }
            curR-- ;
        }
        ans[idx] = answer ;
    }
    for(int &c : ans){
        cout << c << endl;
    }
    return 0; 
}

Compiler output:
a.cc: In function 'int main()':
a.cc:82:32: error: no match for 'operator+' (operand types are 'std::vector<int>' and 'int')
   82 |     debug() << imie(range(v, v + n)) ;
      |                              ~ ^ ~
      |                              |   |
      |                              |   int
      |                              std::vector<int>
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'std::vector<int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   mismatched types 'const _CharT*' and 'std::vector<int>'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'std::vector<int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'std::vector<int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'std::vector<int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'std::vector<int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3696 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   'std::vector<int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro 'imie'
   37 | #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
      |                                                 ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3719 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note:   template argument deduction/substitution failed:
a.cc:82:34: note:   mismatched types 'const _CharT*' and 'std::vector<int>'
   82 |     debug() << imie(range(v, v + n)) ;
      |                                  ^
a.cc:37:49: note: in definition of macro '