Language: C++

#include <iostream>
#include <vector>
using namespace std;
#define boost std::ios_base::sync_with_stdio(0); std::cin.tie(0);

int main()
{
  	boost
    uint16_t n, q;
    cin>>n>>q;
    vector<uint16_t> balls;
    uint16_t ball;
    for(uint16_t i{0}; i!=n; ++i)
    {
        cin>>ball;
        balls.push_back(ball);
    }
    uint16_t tot = 0;
    vector<pair<uint16_t, uint16_t>> queries;
    pair<int, int> query;
    for(uint16_t i{0}; i!=q; ++i)
    {
        cin>>query.first>>query.second;
        queries.push_back(query);
    }
    
    for(pair<uint16_t, uint16_t> query : queries)
    {
        for(uint16_t k{1}; k!=n+1; ++k)
        {
            for(uint16_t j{query.first-1}; j!=query.second; ++j)
            {
                if(k==balls[j])
                {
                    ++tot;
                    break;
                }
            }
        }
        cout<<tot<<"\n";
        tot = 0;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:5: error: 'uint16_t' was not declared in this scope
    9 |     uint16_t n, q;
      |     ^~~~~~~~
a.cc:3:1: note: 'uint16_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    2 | #include <vector>
  +++ |+#include <cstdint>
    3 | using namespace std;
a.cc:10:10: error: 'n' was not declared in this scope
   10 |     cin>>n>>q;
      |          ^
a.cc:10:13: error: 'q' was not declared in this scope
   10 |     cin>>n>>q;
      |             ^
a.cc:11:20: error: template argument 2 is invalid
   11 |     vector<uint16_t> balls;
      |                    ^
a.cc:12:13: error: expected ';' before 'ball'
   12 |     uint16_t ball;
      |             ^~~~~
      |             ;
a.cc:13:17: error: expected ';' before 'i'
   13 |     for(uint16_t i{0}; i!=n; ++i)
      |                 ^~
      |                 ;
a.cc:13:24: error: 'i' was not declared in this scope
   13 |     for(uint16_t i{0}; i!=n; ++i)
      |                        ^
a.cc:15:14: error: 'ball' was not declared in this scope; did you mean 'balls'?
   15 |         cin>>ball;
      |              ^~~~
      |              balls
a.cc:16:15: error: request for member 'push_back' in 'balls', which is of non-class type 'int'
   16 |         balls.push_back(ball);
      |               ^~~~~~~~~
a.cc:18:13: error: expected ';' before 'tot'
   18 |     uint16_t tot = 0;
      |             ^~~~
      |             ;
a.cc:19:35: error: template argument 1 is invalid
   19 |     vector<pair<uint16_t, uint16_t>> queries;
      |                                   ^~
a.cc:19:35: error: template argument 2 is invalid
a.cc:21:17: error: expected ';' before 'i'
   21 |     for(uint16_t i{0}; i!=q; ++i)
      |                 ^~
      |                 ;
a.cc:21:24: error: 'i' was not declared in this scope
   21 |     for(uint16_t i{0}; i!=q; ++i)
      |                        ^
a.cc:24:17: error: request for member 'push_back' in 'queries', which is of non-class type 'int'
   24 |         queries.push_back(query);
      |                 ^~~~~~~~~
a.cc:27:42: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   27 |     for(pair<uint16_t, uint16_t> query : queries)
      |                                          ^~~~~~~
      |                                          std::begin
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:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:27:42: error: 'end' was not declared in this scope; did you mean 'std::end'?
   27 |     for(pair<uint16_t, uint16_t> query : queries)
      |                                          ^~~~~~~
      |                                          std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc:29:21: error: expected ';' before 'k'
   29 |         for(uint16_t k{1}; k!=n+1; ++k)
      |                     ^~
      |                     ;
a.cc:29:28: error: 'k' was not declared in this scope
   29 |         for(uint16_t k{1}; k!=n+1; ++k)
      |                            ^
a.cc:31:25: error: expected ';' before 'j'
   31 |             for(uint16_t j{query.first-1}; j!=query.second; ++j)
      |                         ^~
      |                         ;
a.cc:31:44: error: 'j' was not declared in this scope
   31 |             for(uint16_t j{query.first-1}; j!=query.second; ++j)
      |                                            ^
a.cc:31:53: error: request for member 'second' in 'query', which is of non-class type 'int'
   31 |             for(uint16_t j{query.first-1}; j!=query.second; ++j)
      |                                                     ^~~~~~
a.cc:35:23: error: 'tot' was not declared in this scope
   35 |                     ++tot;
      |                       ^~~
a.cc:40:15: error: 'tot' was not declared in this scope
   40 |         cout<<tot<<"\n";
      |               ^~~