Language: C++

/*
  In the name of ALLAH
  Author : Raashid Anwar
*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
const int M1 =  998244353;
const int M2 =  1000000007;

int l[500001];
int r[500001];
int c[500001];
int a[500001];
int b[500001];
int mp[500001];
int ans[500001];
int n;

void upd(int i, int x) {
  for(; i <= n; i += (i & -i))
    b[i] += x;
}

int get(int i) {
  int sum = 0;
  for(; i; i -= (i & -i))
    sum += b[i];
  return sum;
}

bool comp(int i, int j) {
  return r[i] < r[j];
}

void solve() {
  int q;
  cin >> n >> q;
  for(int i = 1; i <= n; i++)
    b[i] = mp[i] = 0;
  for(int i = 1; i <= n; i++)
    cin >> c[i];
  for(int i = 1; i <= q; i++) {
    cin >> l[i] >> r[i];
    a[i] = i;
  }
  sort(a + 1, a + q + 1, comp);
  int li = 1;
  for(int i = 1; i <= q; i++) {
    while(li <= r[a[i]]) {
      if(mp[c[li]])
        upd(mp[c[li]], -1);
      mp[c[li]] = li;
      upd(li, 1);
      li++;
    }
    ans[a[i]] = get(r[a[i]]) - get(l[a[i]] - 1);
  }
  for(int i = 1; i <= q; i++)
    cout << ans[i] << "\n";
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}/*
  In the name of ALLAH
  Author : Raashid Anwar
*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
const int M1 =  998244353;
const int M2 =  1000000007;

int l[500001];
int r[500001];
int c[500001];
int a[500001];
int b[500001];
int mp[500001];
int ans[500001];
int n;

void upd(int i, int x) {
  for(; i <= n; i += (i & -i))
    b[i] += x;
}

int get(int i) {
  int sum = 0;
  for(; i; i -= (i & -i))
    sum += b[i];
  return sum;
}

bool comp(int i, int j) {
  return r[i] < r[j];
}

void solve() {
  int q;
  cin >> n >> q;
  for(int i = 1; i <= n; i++)
    b[i] = mp[i] = 0;
  for(int i = 1; i <= n; i++)
    cin >> c[i];
  for(int i = 1; i <= q; i++) {
    cin >> l[i] >> r[i];
    a[i] = i;
  }
  sort(a + 1, a + q + 1, comp);
  int li = 1;
  for(int i = 1; i <= q; i++) {
    while(li <= r[a[i]]) {
      if(mp[c[li]])
        upd(mp[c[li]], -1);
      mp[c[li]] = li;
      upd(li, 1);
      li++;
    }
    ans[a[i]] = get(r[a[i]]) - get(l[a[i]] - 1);
  }
  for(int i = 1; i <= q; i++)
    cout << ans[i] << "\n";
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}

Compiler output:
a.cc:78:11: error: redefinition of 'const int64_t M1'
   78 | const int M1 =  998244353;
      |           ^~
a.cc:10:11: note: 'const int64_t M1' previously defined here
   10 | const int M1 =  998244353;
      |           ^~
a.cc:79:11: error: redefinition of 'const int64_t M2'
   79 | const int M2 =  1000000007;
      |           ^~
a.cc:11:11: note: 'const int64_t M2' previously defined here
   11 | const int M2 =  1000000007;
      |           ^~
a.cc:81:5: error: redefinition of 'int64_t l [500001]'
   81 | int l[500001];
      |     ^
a.cc:13:5: note: 'int64_t l [500001]' previously declared here
   13 | int l[500001];
      |     ^
a.cc:82:5: error: redefinition of 'int64_t r [500001]'
   82 | int r[500001];
      |     ^
a.cc:14:5: note: 'int64_t r [500001]' previously declared here
   14 | int r[500001];
      |     ^
a.cc:83:5: error: redefinition of 'int64_t c [500001]'
   83 | int c[500001];
      |     ^
a.cc:15:5: note: 'int64_t c [500001]' previously declared here
   15 | int c[500001];
      |     ^
a.cc:84:5: error: redefinition of 'int64_t a [500001]'
   84 | int a[500001];
      |     ^
a.cc:16:5: note: 'int64_t a [500001]' previously declared here
   16 | int a[500001];
      |     ^
a.cc:85:5: error: redefinition of 'int64_t b [500001]'
   85 | int b[500001];
      |     ^
a.cc:17:5: note: 'int64_t b [500001]' previously declared here
   17 | int b[500001];
      |     ^
a.cc:86:5: error: redefinition of 'int64_t mp [500001]'
   86 | int mp[500001];
      |     ^~
a.cc:18:5: note: 'int64_t mp [500001]' previously declared here
   18 | int mp[500001];
      |     ^~
a.cc:87:5: error: redefinition of 'int64_t ans [500001]'
   87 | int ans[500001];
      |     ^~~
a.cc:19:5: note: 'int64_t ans [500001]' previously declared here
   19 | int ans[500001];
      |     ^~~
a.cc:88:5: error: redefinition of 'int64_t n'
   88 | int n;
      |     ^
a.cc:20:5: note: 'int64_t n' previously declared here
   20 | int n;
      |     ^
a.cc:90:6: error: redefinition of 'void upd(int64_t, int64_t)'
   90 | void upd(int i, int x) {
      |      ^~~
a.cc:22:6: note: 'void upd(int64_t, int64_t)' previously defined here
   22 | void upd(int i, int x) {
      |      ^~~
a.cc:95:5: error: redefinition of 'int64_t get(int64_t)'
   95 | int get(int i) {
      |     ^~~
a.cc:27:5: note: 'int64_t get(int64_t)' previously defined here
   27 | int get(int i) {
      |     ^~~
a.cc:102:6: error: redefinition of 'bool comp(int64_t, int64_t)'
  102 | bool comp(int i, int j) {
      |      ^~~~
a.cc:34:6: note: 'bool comp(int64_t, int64_t)' previously defined here
   34 | bool comp(int i, int j) {
      |      ^~~~
a.cc:106:6: error: redefinition of 'void solve()'
  106 | void solve() {
      |      ^~~~~
a.cc:38:6: note: 'void solve()' previously defined here
   38 | void solve() {
      |      ^~~~~
a.cc:133:9: error: redefinition of 'int32_t main()'
  133 | int32_t main() {
      |         ^~~~
a.cc:65:9: note: 'int32_t main()' previously defined here
   65 | int32_t main() {
      |         ^~~~