Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

// Binary Indexed Tree (Fenwick Tree)
template<typename T> // T: type of cost
struct BIT {
    int n;
    std::vector<T> d;
    BIT(int n=0):n(n),d(n+1) {}
    //配列のインデックスiの要素d[i]に対して、xを加算する。
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) {
            d[i] += x;
        }
    }
    //配列においてインデックスがi以下の要素d[j]たちの和を計算して返す。
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i&-i) {
            x += d[i];
        }
        return x;
    }
};

int main(){
  using namespace std;
  int n, q;
  cin>>n>>q;
  int c[n];
  REP(i, n) cin>>c[i];
  int l[q], r[q];
  REP(i, q){
    cin>>l[i]>>r[i];
    l[i]--; r[i]--;
  }
  
  vector<int> prev(n + 1, -1);
  vector<int> points[500'010];
  REP(i, n){
    if(prev[c[i]] < 0){
      prev[c[i]] = i;
      continue;
    }
    points[prev[c[i]]].push_back(i);
    prev[c[i]] = i;
  }
  
  typedef pair<int, int> P;
  vector<int> queries[500'010];
  REP(i, q) queries[l[i]].push_back(P(r[i], i));
  
  BIT<int> btree(500'010);
  int ans[q];
  for(int x = 500'000; x >= 0; x--){
    for(int y: points[x]) btree.add(y);
    for(P query: queries[x]){
      int y = query.first;
      int i = query.second;
      ans[i] = btree.sum(y);
    }
  }
  REP(i, q) cout << ans[i] << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:116:36: error: no matching function for call to 'std::vector<int>::push_back(P)'
  116 |   REP(i, q) queries[l[i]].push_back(P(r[i], i));
      |             ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'P' {aka 'std::pair<int, int>'} to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'P' {aka 'std::pair<int, int>'} to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:122:27: error: conversion from 'int' to non-scalar type 'P' {aka 'std::pair<int, int>'} requested
  122 |     for(P query: queries[x]){
      |                           ^