Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int INF = 1000000000;

vector< vector<int> > T;
int l, size;

void Stworz(int n, vector<int> a)
{
    int p = 1;
    while (p < n)
        p *= 2;
    l = p;
    size = 2 * p - 1;
    vector<int> x;
    for (int i = 0; i <= size; ++i)
        T.push_back(x);
    for (int i = 0; i < n; ++i)
        T[i + l].push_back(a[i]);
    for (int i = l - 1; i >= 1; --i)
    {
        for (int j = 0; j < T[2 * i].size(); ++j)
            T[i].push_back(T[2 * i][j]);
        for (int j = 0; j < T[2 * i + 1].size(); ++j)
            T[i].push_back(T[2 * i + 1][j]);
        sort(T[i].begin(), T[i].end());
    }
}

int Ile(vector<int>& a, int x)
{
    int l = 0, p = a.size() - 1, s, r = -1;
    while (l <= p)
    {
        s = (l + p) / 2;
        if (a[s] >= x)
        {
            r = s;
            p = s - 1;
        }
        else
            l = s + 1;
    }
    if (r == -1)
        return 0;
    return a.size() - r;
}

int Pyt(int a, int b)
{
    int ogr = b + 1;
    a += l;
    b += l;
    int wyn = Ile(T[a], ogr);
    if (a != b)
        wyn += Ile(T[b], ogr);
    while (a / 2 != b / 2)
    {
        if (a % 2 == 0)
            wyn += Ile(T[a + 1], ogr);
        if (b % 2 == 1)
            wyn += Ile(T[b - 1], ogr);
        a /= 2;
        b /= 2;
    }
    return wyn;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        --a[i];
    }
    vector<int> nast(n, INF);
    vector<int> b(n);
    for (int i = n - 1; i >= 0; --i)
    {
        b[i] = nast[a[i]];
        nast[a[i]] = i;
    }
    Stworz(n, b);
    for (int i = 0; i < q; ++i)
    {
        int l, r;
        cin >> l >> r;
        --l;
        --r;
        cout << Pyt(l, r) << endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'void Stworz(int, std::vector<int>)':
a.cc:18:5: error: reference to 'size' is ambiguous
   18 |     size = 2 * p - 1;
      |     ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:8: note:                 'int size'
   10 | int l, size;
      |        ^~~~
a.cc:20:26: error: reference to 'size' is ambiguous
   20 |     for (int i = 0; i <= size; ++i)
      |                          ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:10:8: note:                 'int size'
   10 | int l, size;
      |        ^~~~