Language: C++

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
int i;
#define rep2(i, a, b) for(i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
using namespace std;
// _________コーディングはここから！！___________
template <const int sz = 5 * 10000000, typename T = long long> struct IO {
    char reader[sz], writer[sz];
    char *now, *now2 = writer;
    IO() {
        reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
        now = reader;
    }
    inline T read() {
        while(*now && *now <= 32) now++;
        if(*now == '-') {
            now++;
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return -res;
        } else {
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return res;
        }
    }
    inline string read_str() {
        string res;
        while(*now and *now != '\n' and *now != ' ') res += *now++;
        now++;
        return res;
    }
    inline void write(T x, char margin = ' ') {
        if(x == 0) {
            putchar('0');
            putchar(margin);
            return;
        }
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        while(x) {
            *now2 = '0' + x % 10;
            now2++;
            x /= 10;
        }
        do {
            now2--;
            putchar(*now2);
        } while(now2 != writer);
        putchar(margin);
    }
    inline void write_str(string s, char margin = ' ') {
        for(auto c : s) putchar(c);
        putchar(margin);
    }
};
IO io;
inline int read() { return io.read(); }
inline void write(int x) { io.write(x); }
inline void write(int x, char c) { io.write(x, c); }
constexpr int N = 500003;
int c[N];
struct T {
    int l, r, idx;
    constexpr bool operator<(const T &rhs) const noexcept { return r < rhs.r; }
} q[N];
int ans[N], last[N], dat[N];

inline void dec(int k) {
    for(++k; k < N; k += k & -k) --dat[k];
}
inline int sum(int k) {
    int res = 0;
    for(++k; k > 0; k -= k & -k) res += dat[k];
    return res;
}
int n, Q, now = 1;

// 頑張れ！！
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
// 頑張れ！！

// vector<int> l[N], idx[N];
vector<pii> v[N];
int L, R;
main() {
    n = read(), Q = read();
    rep2(i, 1, n) c[i] = read();
    rep(i, Q) {
        L = read();
        v[read()].emplace_back(L, i);
    }
    rep2(i, 1, n) {
        if(last[c[i]]) dec(last[c[i]]);
        last[c[i]] = i;
        for(auto [l, idx] : v[i]) ans[idx] = sum(i) - sum(l - 1) + i - l + 1;
    }
    // rep(i, Q) {
    //     for(; now < q[i].r; ++now) {
    //         if(last[c[now]]) dec(last[c[now]]);
    //         last[c[now]] = now;
    //     }
    //     ans[q[i].idx] = sum(q[i].r - 1) - sum(q[i].l - 1) + q[i].r - q[i].l;
    // }
    rep(i, Q) write(ans[i], '\n');
}


Compiler output:
a.cc:88:8: error: 'pii' was not declared in this scope
   88 | vector<pii> v[N];
      |        ^~~
a.cc:88:11: error: template argument 1 is invalid
   88 | vector<pii> v[N];
      |           ^
a.cc:88:11: error: template argument 2 is invalid
a.cc:90:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   90 | main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:95:19: error: request for member 'emplace_back' in 'v[read()]', which is of non-class type 'int'
   95 |         v[read()].emplace_back(L, i);
      |                   ^~~~~~~~~~~~
a.cc:100:32: error: 'begin' was not declared in this scope
  100 |         for(auto [l, idx] : v[i]) ans[idx] = sum(i) - sum(l - 1) + i - l + 1;
      |                                ^
a.cc:100:32: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:2:
/usr/include/c++/14/valarray:1238:5: note:   'std::begin'
 1238 |     begin(const valarray<_Tp>& __va) noexcept
      |     ^~~~~
In file included from /usr/include/c++/14/filesystem:53,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:200:
/usr/include/c++/14/bits/fs_dir.h:608:3: note:   'std::filesystem::__cxx11::begin'
  608 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
a.cc:100:32: error: 'end' was not declared in this scope
  100 |         for(auto [l, idx] : v[i]) ans[idx] = sum(i) - sum(l - 1) + i - l + 1;
      |                                ^
a.cc:100:32: note: suggested alternatives:
/usr/include/c++/14/valarray:1265:5: note:   'std::end'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/fs_dir.h:613:3: note:   'std::filesystem::__cxx11::end'
  613 |   end(recursive_directory_iterator) noexcept
      |   ^~~