Language: C++

/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}


double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

/*
* @title Mo's Algorithm
* @docs kyopro/docs/mo.md
*/

template<typename ADD, typename DEL, typename REM, typename T = int>
struct mo {
	int sqn, q, l, r, p;
	T ret;
	vector<tuple<int, int, int>> query;
	vector<T> ans;
	const ADD add;
	const DEL del;
	const REM rem;

	mo(int n, int q, ADD add, DEL del, REM rem) : sqn((int)sqrt(n)), q(q), l(0), r(0), p(0), ret(T(0)), query(q), ans(q), add(add), del(del), rem(rem) {}

	void insert(int l, int r) {
		query[p] = { l, r, p++ };
	}

	void read(bool oneindexed) {
		for (auto& [left, right, idx] : query) {
			scanf("%d%d", &left, &right);
			if (oneindexed)--left;
			idx = p++;
		}
	}

	void build() {
		sort(all(query), [&](const tuple<int, int, int>& a, const tuple<int, int, int>& b) {
			const auto& [al, ar, ao] = a;
			const auto& [bl, br, bo] = b;
			if (al / sqn != bl / sqn)return al < bl;
			return ar < br;
			});
	}

	void run() {
		for (const auto& [ql, qr, qo] : query) {
			while (l > ql)add(--l, ret);
			while (r < qr)add(r++, ret);
			while (l < ql)del(l++, ret);
			while (r > qr)del(--r, ret);
			rem(qo, ans, ret);
		}
	}

	T operator [](const int& idx) {
		return ans[idx];
	}

	void allrun(const bool& oneindexed) {
		read(oneindexed);
		build();
		run();
	}

};
vector<int> a(5e5);
vector<int> memo(5e5);
inline auto add = [&](const int& idx, int& ret) {if (memo[a[idx]]++ == 0)++ret; };
inline auto del = [&](const int& idx, int& ret) {if (--memo[a[idx]] == 0)--ret; };
inline auto rem = [](const int& idx, vector<int>& ans, const int& ret) {ans[idx] = ret; };

int main() {

	int n, q;
	scanf("%d%d", &n, &q);
	rep(i, n) {
		scanf("%d", &a[i]);
		--a[i];
	}

	mo<decltype(add), decltype(del), decltype(rem)> m(n, q, add, del, rem);
	m.allrun(true);
	rep(i, q)printf("%d\n", m[i]);

	Please AC;
}


Compiler output:
a.cc:176:20: error: non-local lambda expression cannot have a capture-default
  176 | inline auto add = [&](const int& idx, int& ret) {if (memo[a[idx]]++ == 0)++ret; };
      |                    ^
a.cc:177:20: error: non-local lambda expression cannot have a capture-default
  177 | inline auto del = [&](const int& idx, int& ret) {if (--memo[a[idx]] == 0)--ret; };
      |                    ^