Language: C++

a#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

const int sqr = 700;
int n, q, arr[500005], ans[500005], l, r, occ[500005], cur;
vpii Q;

bool cmp(pii a, pii b) {
	if (a.f.f/sqr != b.f.f/sqr) return a.f.f < b.f.f;
	return (a.f.f/sqr % 2 ? a.f.s < b.f.s : a.f.s > b.f.s);
}

void add(int x) {
	occ[arr[x]]++;
	cur += (occ[arr[x]] == 1);
}

void rem(int x) {
	occ[arr[x]]--;
	cur -= (occ[arr[x]] == 0);
}

int main() {
	fastio; cin >> n >> q;
	FOR(i, 1, n) cin >> arr[i];
	FOR(i, 1, q) {
		int a, b; cin >> a >> b;
		Q.pb(pii(pi(a, b), i));
	}
	sort(all(Q), cmp);
	for (auto it:Q) {
		int a = it.f.f, b = it.f.s, idx = it.s;
		while (r < b) add(++r);
		while (l > a) add(--l);
		while (r > b) rem(r--);
		while (l < a) rem(l++);
		ans[idx] = cur;
	}
	FOR(i, 1, q) cout << ans[i] << "\n";
}


Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | a#include <bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'a' does not name a type
    1 | a#include <bits/stdc++.h>
      | ^
a.cc:7:9: error: 'pair' does not name a type
    7 | typedef pair<int, int> pi;
      |         ^~~~
a.cc:8:9: error: 'pair' does not name a type
    8 | typedef pair<pi, int> pii;
      |         ^~~~
a.cc:9:9: error: 'pair' does not name a type
    9 | typedef pair<pi, pi> pipi;
      |         ^~~~
a.cc:12:9: error: 'vector' does not name a type
   12 | typedef vector<int> vi;
      |         ^~~~~~
a.cc:13:9: error: 'vector' does not name a type
   13 | typedef vector<pi> vpi;
      |         ^~~~~~
a.cc:14:9: error: 'vector' does not name a type
   14 | typedef vector<pii> vpii;
      |         ^~~~~~
a.cc:22:1: error: 'mt19937' does not name a type
   22 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
      | ^~~~~~~
a.cc: In function 'll rand(ll, ll)':
a.cc:23:43: error: 'rng' was not declared in this scope
   23 | inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
      |                                           ^~~
a.cc: At global scope:
a.cc:27:1: error: 'vpii' does not name a type
   27 | vpii Q;
      | ^~~~
a.cc:29:10: error: 'pii' was not declared in this scope
   29 | bool cmp(pii a, pii b) {
      |          ^~~
a.cc:29:17: error: 'pii' was not declared in this scope
   29 | bool cmp(pii a, pii b) {
      |                 ^~~
a.cc:29:22: error: expression list treated as compound expression in initializer [-fpermissive]
   29 | bool cmp(pii a, pii b) {
      |                      ^
a.cc: In function 'int main()':
a.cc:21:16: error: 'ios_base' has not been declared
   21 | #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
      |                ^~~~~~~~
a.cc:45:9: note: in expansion of macro 'fastio'
   45 |         fastio; cin >> n >> q;
      |         ^~~~~~
a.cc:21:46: error: 'cin' was not declared in this scope
   21 | #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
      |                                              ^~~
a.cc:45:9: note: in expansion of macro 'fastio'
   45 |         fastio; cin >> n >> q;
      |         ^~~~~~
a.cc:21:58: error: 'cout' was not declared in this scope
   21 | #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
      |                                                          ^~~~
a.cc:45:9: note: in expansion of macro 'fastio'
   45 |         fastio; cin >> n >> q;
      |         ^~~~~~
a.cc:49:17: error: 'Q' was not declared in this scope
   49 |                 Q.pb(pii(pi(a, b), i));
      |                 ^
a.cc:49:26: error: 'pi' was not declared in this scope; did you mean 'i'?
   49 |                 Q.pb(pii(pi(a, b), i));
      |                          ^~
      |                          i
a.cc:49:22: error: 'pii' was not declared in this scope
   49 |                 Q.pb(pii(pi(a, b), i));
      |                      ^~~
a.cc:51:18: error: 'Q' was not declared in this scope
   51 |         sort(all(Q), cmp);
      |                  ^
a.cc:17:16: note: in definition of macro 'all'
   17 | #define all(v) v.begin(), v.end()
      |                ^
a.cc:51:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   51 |         sort(all(Q), cmp);
      |         ^~~~
      |         short
a.cc:54:28: error: 'b' was not declared in this scope
   54 |                 while (r < b) add(++r);
      |                            ^
a.cc:56:28: error: 'b' was not declared in this scope
   56 |                 while (r > b) rem(r--);
      |                            ^
a.cc:58:21: error: 'idx' was not declared in this scope
   58 |                 ans[idx] = cur;
      |                     ^~~