Language: C++

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

int data[5 * int(1e5) + 10];
void update(int x, int d) {
    for ( ; x < 5 * int(1e5) + 10; x += (x & (-x)) ) data[x] += d;
}
int sum(int x) {
    int result = 0;
    for ( ; 0 < x; x -= (x & (-x)) ) result += data[x];
    return result;
}
int rangesum(int l, int r) { // [l, r]
    return sum(r) - sum(l-1);
}


int N, nQ;
vector<int> Query[5 * int(1e5) + 10], Qid[5 * int(1e5) + 10];

vector<int> c;

void solve() {
    cin >> N >> nQ;
    c.resize(N + 1);
    for (int i = 1; i <= N; i++) cin >> c[i];

    for (int i = 1; i <= nQ; i++) {
        int l, r;
        cin >> l >> r;
        l, r;
        Query[l].push_back(r);
        Qid[l].push_back(i - 1);
    }

    vector<int> lastSeen (5 * int(1e5) + 10, 0);
    vector<int> answer (nQ);
    for (int L = N; L > 0; L--) {
        if (lastSeen[c[L]] == 0); 
        else update(lastSeen[c[L]], -1);
        
        lastSeen[c[L]] = L;
        update(L, 1);

        for (int iq = 0; iq < (int) Query[L].size(); iq++) {
            answer[Qid[L][iq]] = rangesum(L, Query[L][iq]);
        }
    }

    for (int a : answer) {
        cout << a << '\n';
    }
}

int main() {
    ios::sync_with_stdio(0);
    solve();
}

Compiler output:
a.cc: In function 'void update(int, int)':
a.cc:6:54: error: reference to 'data' is ambiguous
    6 |     for ( ; x < 5 * int(1e5) + 10; x += (x & (-x)) ) data[x] += d;
      |                                                      ^~~~
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:4:5: note:                 'int data [500010]'
    4 | int data[5 * int(1e5) + 10];
      |     ^~~~
a.cc: In function 'int sum(int)':
a.cc:10:48: error: reference to 'data' is ambiguous
   10 |     for ( ; 0 < x; x -= (x & (-x)) ) result += data[x];
      |                                                ^~~~
/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:4:5: note:                 'int data [500010]'
    4 | int data[5 * int(1e5) + 10];
      |     ^~~~