Language: C++

#pragma GCC optimize("O3")
//#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


struct Mo {

    int width;
    vector< int > left, right, order;
    vector< bool > v;

    Mo(int N, int Q) : width((int)sqrt(N)), order(Q), v(N) {
        iota(begin(order), end(order), 0);
    }

    void add(int l, int r) { // [l, r) 
        left.emplace_back(l);
        right.emplace_back(r);
    }

    template<class ADD, class DEL, class REM>
    int run(const ADD& add, const DEL& del, const REM& rem) {
        assert(left.size() == order.size());
        sort(begin(order), end(order), [&](int a, int b) {
            int ablock = left[a] / width, bblock = left[b] / width;
            if (ablock != bblock) return ablock < bblock;
            if (ablock & 1) return right[a] < right[b];
            return right[a] > right[b];
            });
        int nl = 0, nr = 0;
        auto push = [&](int idx) {
            v[idx].flip();
            if (v[idx]) add(idx);
            else del(idx);
        };
        for (auto idx : order) {
            while (nl > left[idx]) push(--nl);
            while (nr < right[idx]) push(nr++);
            while (nl < left[idx]) push(nl++);
            while (nr > right[idx]) push(--nr);
            rem(idx);
        }
        return 0;
    }
};
int main() {
    io_init;
    int N, Q;
    cin >> N;
    cin >> Q;

    vector< int > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector< int > f(1000001);
    Mo mo(N, Q);
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        mo.add(--l, r);
    }
    int ret = 0;
    auto add = [&](int idx) { if (f[A[idx]]++ == 0) ret++; };
    auto del = [&](int idx) { if (f[A[idx]]-- == 1) --ret; };
    vector< int > ans(Q);
    auto rem = [&](int idx) { ans[idx] = ret; };
    mo.run(add, del, rem);
    for (int i = 0; i < Q; i++) {
        cout << ans[i] << "\n";
    }
}


Compiler output:
a.cc:19:15: error: redefinition of 'constexpr const int INF'
   19 | constexpr int INF = 2147483647;
      |               ^~~
a.cc:6:15: note: 'constexpr const int INF' previously defined here
    6 | constexpr int INF = 2147483647;
      |               ^~~
a.cc:20:25: error: redefinition of 'constexpr const long long int INF_LL'
   20 | constexpr long long int INF_LL = 9223372036854775807;
      |                         ^~~~~~
a.cc:7:25: note: 'constexpr const long long int INF_LL' previously defined here
    7 | constexpr long long int INF_LL = 9223372036854775807;
      |                         ^~~~~~
a.cc:21:15: error: redefinition of 'constexpr const int MOD'
   21 | constexpr int MOD = 1000000007;
      |               ^~~
a.cc:8:15: note: 'constexpr const int MOD' previously defined here
    8 | constexpr int MOD = 1000000007;
      |               ^~~
a.cc:22:18: error: redefinition of 'constexpr const double PI'
   22 | constexpr double PI = 3.14159265358979323846;
      |                  ^~
a.cc:9:18: note: 'constexpr const double PI' previously defined here
    9 | constexpr double PI = 3.14159265358979323846;
      |                  ^~