criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
 
using namespace std;
 
struct Query {
  int lo, hi, idx;
  Query(int lo, int hi, int idx) : lo(lo), hi(hi), idx(idx) {}
};
 
int n, m, A[100010], cnt[1000010], ans[100010], distinctNumbers;
vector<Query> query;
 
// add function
void add(int num) {
  // num이 새롭게 cnt배열에 들어올때만 카운팅 해준다
  if (++cnt[num] == 1) {
    ++distinctNumbers;
  }
}
 
// erase function
void erase(int num) {
  // num이 cnt배열에서 완전히 없어질때 카운팅 해준다
  if (--cnt[num] == 0) {
    --distinctNumbers;
  }
}
 
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0 ; i < n ; ++i) {
    scanf("%d", &A[i]);
  }
  
  for (int i = 0 ; i < m ; ++i) {
    int lo, hi;
    scanf("%d%d", &lo, &hi);
    query.emplace_back(lo - 1, hi - 1, i);
  }
   
  // sort queries
  int sz = sqrt(n);
  sort(query.begin(), query.end(), [&](const Query& l, const Query& r) {
    // 쿼리가 끝나는 부분이 어떠한 묶음에 속하는지 확인하다
    // 묶음의 인덱스가 더 작은곳에 속하는 쿼리를 먼저 처리한다
    // 만약 묶음의 인덱스가 같다면 쿼리의 시작지점이 작은것을 먼저 처리한다
    int lIdx = l.hi / sz;
    int rIdx = r.hi / sz;
    return lIdx == rIdx ? l.lo < r.lo : lIdx < rIdx;
  });
   
  // Change the iterator from the previous query to the current query
  int lo = 0, hi = 0;
   
  // 시작 이터레이터는 [0, 0]이기 때문에 A[0]의 값을 cnt배열에 넣고 시작한다
  add(A[0]);
   
  // 모든 쿼리에 대한 답을 계산한다
  for (auto cur : query) {
    // 현재 위치는 [lo, hi]이고 다음 위치는 [nlo, nhi]이다
    int nlo = cur.lo, nhi = cur.hi;
     
    // lo를 nlo로 움직이는 부분
    // 1. lo가 nlo보다 왼쪽에 있는 경우 : 수를 제거할 필요가 있다
    for (int i = lo ; i < nlo ; ++i) {
      erase(A[i]);
    }
     
    // 2. lo가 nlo보다 오른쪽에 있는 경우 : 수를 더할 필요가 있다
    for (int i = lo - 1; i >= nlo ; --i) {
      add(A[i]);
    }
     
    // hi를 nhi로 움직이는 부분
    // 1. hi가 nhi보다 왼쪽에 있는 경우 : 수를 더할 필요가 있다
    for (int i = hi + 1 ; i <= nhi ; ++i) {
      add(A[i]);
    }
     
    // 2. hi가 nhi보다 오른쪽에 있는 경우 : 수를 제거할 필요가 있다
    for (int i = hi ; i > nhi ; --i) {
      erase(A[i]);
    }
     
    // 이터레이터가 현재 쿼리의 범위를 나타내도록 한다
    lo = nlo;
    hi = nhi;
     
    // 답을 저장할 배열에 실제 쿼리의 순서에 맞게 답을 기록해 준다
    ans[cur.idx] = distinctNumbers;
  }
   
  for (int i = 0 ; i < m ; ++i) {
    printf("%d\n", ans[i]);
  }
}


출처: https://kesakiyo.tistory.com/25 [Problem Solving]

출처: https://kesakiyo.tistory.com/25 [Problem Solving]

출처: https://kesakiyo.tistory.com/25 [Problem Solving]

Compiler output:
a.cc:103:5: error: found ':' in nested-name-specifier, expected '::'
  103 | 출처: https://kesakiyo.tistory.com/25 [Problem Solving]
      |     ^
      |     ::
a.cc:103:1: error: '\U0000cd9c\U0000cc98' does not name a type
  103 | 출처: https://kesakiyo.tistory.com/25 [Problem Solving]
      | ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){long n,s;cin>>n>>s;
vector<long>a(s);for(int i=0;i<n;i++){cin>>a.at(i);
for(int i=0;i<s;i++)long l,r,q=0;cin>>l>>r;
vector<int>p(n);
 for(long j=l-1;j<r;j++){if(p.at(j)==0){p.at(j)=1;q++;}}cout<<q<<endl;}}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:39: error: 'l' was not declared in this scope
    5 | for(int i=0;i<s;i++)long l,r,q=0;cin>>l>>r;
      |                                       ^
a.cc:5:42: error: 'r' was not declared in this scope
    5 | for(int i=0;i<s;i++)long l,r,q=0;cin>>l>>r;
      |                                          ^
a.cc:7:51: error: 'q' was not declared in this scope
    7 |  for(long j=l-1;j<r;j++){if(p.at(j)==0){p.at(j)=1;q++;}}cout<<q<<endl;}}
      |                                                   ^
a.cc:7:63: error: 'q' was not declared in this scope
    7 |  for(long j=l-1;j<r;j++){if(p.at(j)==0){p.at(j)=1;q++;}}cout<<q<<endl;}}
      |                                                               ^
Language: C

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
using namespace std;

struct Mo {
    vector<int> left, right, index; // the interval's left, right, index
    vector<bool> v;
    int window;
    int nl, nr, ptr;
    
    Mo(int n) : window((int)sqrt(n)), nl(0), nr(0), ptr(0), v(n, false) { }
    
    /* push */
    void push(int l, int r) { left.push_back(l), right.push_back(r); }
    
    /* sort intervals */
    void build() {
        index.resize(left.size());
        iota(index.begin(), index.end(), 0);
        sort(begin(index), end(index), [&](int a, int b)
        {
            if (left[a] / window != left[b] / window) return left[a] < left[b];
            return bool((right[a] < right[b]) ^ (left[a] / window % 2));
        });
        
        //        sort(index.begin(), index.end(), [&](int a, int b) {
        //            if (left[a] / window != right[b] / window) return left[a] < left[b];
        //            else return right[a] < right[b];
        //        });
    }
    
    /* extend-shorten */
    void extend_shorten(int id) {
        v[id].flip();
        if (v[id]) insert(id);
        else erase(id);
    }
    
    /* next id of interval */
    int next() {
        if (ptr == index.size()) return -1;
        int id = index[ptr];
        while (nl > left[id]) extend_shorten(--nl);
        while (nr < right[id]) extend_shorten(nr++);
        while (nl < left[id]) extend_shorten(nl++);
        while (nr > right[id]) extend_shorten(--nr);
        return index[ptr++];
    }
    
    /* insert, erase (to be set appropriately) */
    void insert(int id);
    void erase(int id);
};

int N, Q;
int A[500001];
int res[500001];
int cnt[1000001];
int num_kind = 0;

void Mo::insert(int id) {
    int val = A[id];
    if (cnt[val] == 0) ++num_kind;
    ++cnt[val];
}

void Mo::erase(int id) {
    int val = A[id];
    --cnt[val];
    if (cnt[val] == 0) --num_kind;
}

int main() {
    scanf("%d", &N);
    scanf("%d", &Q);
    for(int i = 0; i < N; i++) scanf("%d", &A[i]);
    Mo mo(N);
    for(int i = 0; i < Q; i++) {
        int l, r; scanf("%d %d", &l, &r);
        mo.push(--l, r);
    }
    mo.build();
    for(int i = 0; i < Q; i++) res[mo.next()] = num_kind;
    for(int i = 0; i < Q; i++) printf("%d\n", res[i]);
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){long n,s;cin>>n>>s;
vector<long>a(s) for(int i=0;i<n;i++){cin>>a.at(i);
for(int i=0;i<s;i++)long l,r,q=0;cin>>l>>r;
vector<int>p(n);
 for(long j=l-1;j<r;j++){if(p.at(j)==0){p.at(j)=1;q++;}}cout<<q<<endl;}}

Compiler output:
a.cc: In function 'int main()':
a.cc:4:18: error: expected ',' or ';' before 'for'
    4 | vector<long>a(s) for(int i=0;i<n;i++){cin>>a.at(i);
      |                  ^~~
a.cc:4:30: error: 'i' was not declared in this scope
    4 | vector<long>a(s) for(int i=0;i<n;i++){cin>>a.at(i);
      |                              ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
long n,s;cin>>n>>s;
vector<long>a(s) for(int i=0;i<n;i++){cin>>a.at(i);
for(int i=0;i<s;i++)long l,r,q=0;cin>>l>>r;
vector<int>p(n);
 for(long j=l-1;j<r;j++){if(p.at(j)==0){p.at(j)=1;q++;}}cout<<q<<endl;}}

Compiler output:
a.cc:3:10: error: 'cin' does not name a type
    3 | long n,s;cin>>n>>s;
      |          ^~~
a.cc:4:18: error: expected ',' or ';' before 'for'
    4 | vector<long>a(s) for(int i=0;i<n;i++){cin>>a.at(i);
      |                  ^~~
a.cc:4:30: error: 'i' does not name a type
    4 | vector<long>a(s) for(int i=0;i<n;i++){cin>>a.at(i);
      |                              ^
a.cc:4:34: error: 'i' does not name a type
    4 | vector<long>a(s) for(int i=0;i<n;i++){cin>>a.at(i);
      |                                  ^
a.cc:7:72: error: expected declaration before '}' token
    7 |  for(long j=l-1;j<r;j++){if(p.at(j)==0){p.at(j)=1;q++;}}cout<<q<<endl;}}
      |                                                                        ^
Language: C++

#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<ll, ll>;
ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n, ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2, mod) % mod);
	else
		return (x * pow(x, n - 1, mod) % mod);
}
signed main() {
	int n, q; cin >> n >> q;
	vector<int>c(n);
	rip(i, n)cin >> c[i];
	vector<int>nam(n);
	set<int>p;
	rip(i, n) {
		p.insert(c[i]);
		nam[i] = p.size();
	}
	while (q--) {
		int l, r; cin >> l >> r;
      l--,r--;
		set<ll>q;
		rip(i, l, r+1)q.insert(c[i]);
		ll ans = q.size();
		cout << ans << endl;
	}
}


Compiler output:
a.cc:69:30: error: macro "rip" passed 3 arguments, but takes just 2
   69 |                 rip(i, l, r+1)q.insert(c[i]);
      |                              ^
a.cc:21:9: note: macro "rip" defined here
   21 | #define rip(i,n) for(int i=0;i<n;i++)
      |         ^~~
a.cc: In function 'int main()':
a.cc:69:17: error: 'rip' was not declared in this scope
   69 |                 rip(i, l, r+1)q.insert(c[i]);
      |                 ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int MAXN = 1000001;
int arr[maxN];
set<int> st[4 * maxN];
void build(int si, int ss, int se){
    if(ss == se){
        st[si].insert(arr[ss]);
        return;
    }
    int mid = (ss + se) / 2;
    build(2 * si, ss, mid);
    build(2 * si + 1, mid + 1, se);
    st[si].insert(st[2 * si].begin(), st[2 * si].end());
    st[si].insert(st[2 * si + 1].begin(), st[2 * si + 1].end());
}
set<int> query(int si, int ss, int se, int qs, int qe){
    set<int> l, r, res;
    if(qs > se || qe < ss) return res;
    if(qs <= ss && qe >= se) return st[si];
    int mid = (ss + se) / 2;
    l = query(2 * si, ss, mid, qs, qe);
    r = query(2 * si + 1, mid + 1, se, qs, qe);
    res.insert(l.begin(), l.end());
    res.insert(r.begin(), r.end());
    return res;
}
int32_t main(){
    SPEED;
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) cin >> arr[i];
    build(1, 1, n);
    vpp qu;
    while(m--){
        int l, r;
        cin >> l >> r;
        qu.pb({l, r});
        set<int> ans = query(1, 1, n, l, r);
        cout << ans.size() << endl;
    }
}

Compiler output:
a.cc:12:9: error: 'maxN' was not declared in this scope
   12 | int arr[maxN];
      |         ^~~~
a.cc:13:17: error: 'maxN' was not declared in this scope
   13 | set<int> st[4 * maxN];
      |                 ^~~~
a.cc: In function 'void build(long long int, long long int, long long int)':
a.cc:16:9: error: 'st' was not declared in this scope; did you mean 'si'?
   16 |         st[si].insert(arr[ss]);
      |         ^~
      |         si
a.cc:16:23: error: 'arr' was not declared in this scope
   16 |         st[si].insert(arr[ss]);
      |                       ^~~
a.cc:22:5: error: 'st' was not declared in this scope; did you mean 'si'?
   22 |     st[si].insert(st[2 * si].begin(), st[2 * si].end());
      |     ^~
      |     si
a.cc: In function 'std::set<long long int> query(long long int, long long int, long long int, long long int, long long int)':
a.cc:28:37: error: 'st' was not declared in this scope; did you mean 'si'?
   28 |     if(qs <= ss && qe >= se) return st[si];
      |                                     ^~
      |                                     si
a.cc: In function 'int32_t main()':
a.cc:40:40: error: 'arr' was not declared in this scope
   40 |     for(int i = 1; i <= n; ++i) cin >> arr[i];
      |                                        ^~~
a.cc:42:5: error: 'vpp' was not declared in this scope
   42 |     vpp qu;
      |     ^~~
a.cc:46:9: error: 'qu' was not declared in this scope
   46 |         qu.pb({l, r});
      |         ^~
Language: C++

#include<bits/stdc++.h>

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

void merge(vector<int> tree[], 
				int treeNode) 
{ 
	int len1 = 
	tree[2 * treeNode].size(); 
	int len2 = 
	tree[2 * treeNode + 1].size(); 
	int index1 = 0, index2 = 0; 

	while (index1 < len1 && index2 < len2) { 

		if (tree[2 * treeNode][index1] > 
			tree[2 * treeNode + 1][index2]) { 

			tree[treeNode].push_back( 
				tree[2 * treeNode + 1][index2] 
				); 
			index2++; 
		} 
		else { 
			tree[treeNode].push_back( 
				tree[2 * treeNode][index1] 
				); 
			index1++; 
		} 
	} 

	while (index1 < len1) { 
		tree[treeNode].push_back( 
			tree[2 * treeNode][index1] 
			); 
		index1++; 
	} 

	while (index2 < len2) { 
		tree[treeNode].push_back( 
			tree[2 * treeNode + 1][index2] 
			); 
		index2++; 
	} 
	return; 
} 

void build(vector<int> tree[], 
	int* arr, int start, int end, 
				int treeNode) 
{ 
	if (start == end) { 
		tree[treeNode].push_back( 
			arr[start]); 
		return; 
	} 
	int mid = (start + end) / 2; 

	build(tree, arr, start, 
		mid, 2 * treeNode); 

	build(tree, arr, mid + 1, end, 
				2 * treeNode + 1); 

	merge(tree, treeNode); 
	return; 
} 

int query(vector<int> tree[], 
	int treeNode, int start, int end, 
			int left, int right) 
{ 

	if (start > right || end < left) { 
		return 0; 
	} 

	if (start >= left && end <= right) { 
 
		return tree[treeNode].end() - 
		upper_bound(tree[treeNode].begin(), 
			tree[treeNode].end(), right); 
	} 

	int mid = (start + end) / 2; 

	int op1 = query(tree, 2 * treeNode, 
			start, mid, left, right); 

	int op2 = query(tree, 2 * treeNode + 1, 
			mid + 1, end, left, right); 
	return op1 + op2; 
} 

int main() 
{ 
	IOS;
	int n, m; cin >> n >> m;
	int arr[n];
	for(int i = 0; i < n; i++) cin >> arr[i];

	int next_right[n]; 
	
	vector<int> tree[4 * n]; 

	unordered_map<int, int> ump; 

	for (int i = n - 1; i >= 0; i--) { 
		if (ump[arr[i]] == 0) { 
			next_right[i] = n; 
			ump[arr[i]] = i; 
		} 
		else { 
			next_right[i] = ump[arr[i]]; 
			ump[arr[i]] = i; 
		} 
	} 

	build(tree, next_right, 0, n - 1, 1); 

	int ans; 
	while(m--){
	int left1, right1; cin >> left1 >> right1;
	left1--, right1--;
	ans = query(tree, 1, 0, n - 1, 
				left1, right1); 
		cout << ans << endl; 
	}
	return 0;
} 


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAX = 1000001;

// structure to store queries
struct Query
{
	ll l, r, idx;
};

// cmp function to sort queries according to r
bool cmp(Query x, Query y)
{
	return x.r < y.r;
}

// updating the bit array
void update(ll idx, ll val, ll bit[], ll n)
{
	for (; idx <= n; idx += idx&-idx)
		bit[idx] += val;
}

// querying the bit array
ll query(ll idx, ll bit[], ll n)
{
	ll sum = 0;
	for (; idx>0; idx-=idx&-idx)
		sum += bit[idx];
	return sum;
}



// driver code
int main()
{
	ll n ,q;
	cin>>n>>q;
	ll a[n];
	for(ll i=0;i<n;i++){
        cin>>a[i];
	}
	Query queries[q];
	for(ll i=0;i<q;i++){
            ll u,v;
    cin>>u>>v;
	queries[0].l = u-1;
	queries[0].r = v-1;
	queries[i].idx = i;
	}
	ll test=2000,pip=0;
	while(test--){
        pip++;
	}
	sort(queries, queries+q, cmp);
	ll bit[n+1]={0};


	// holds the rightmost index of any number
	// as numbers of a[i] are less than or equal to 10^6
	ll last_visit[MAX]={-1};


	// answer for each query
	ll ans[q];
	ll query_counter = 0;
	for (int i=0; i<n; i++)
	{

		if (last_visit[arr[i]] !=-1)
			update (last_visit[arr[i]] + 1, -1, bit, n);
		last_visit[arr[i]] = i;
		update(i + 1, 1, bit, n);

		while (query_counter < q && queries[query_counter].r == i)
		{
			ans[queries[query_counter].idx] =
					query(queries[query_counter].r + 1, bit, n)-
					query(queries[query_counter].l, bit, n);
			query_counter++;
		}
	}

	for (ll i=0; i<q; i++)
		cout << ans[i] << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:73:32: error: 'arr' was not declared in this scope
   73 |                 if (last_visit[arr[i]] !=-1)
      |                                ^~~
a.cc:75:28: error: 'arr' was not declared in this scope
   75 |                 last_visit[arr[i]] = i;
      |                            ^~~
Language: C++

#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<set>
#include<algorithm>
using namespace std;
int N, M, A[100000], ans[100000];
int reach[100001], sum[200001], now;

struct Mo
{
  vector< int > left, right, order;
  vector< bool > v;
  int width;
  int nl, nr, ptr;

  Mo(int n) : width((int) sqrt(n)), nl(0), nr(0), ptr(0), v(n) {}

  void insert(int l, int r) /* [l, r) */
  {
    left.push_back(l);
    right.push_back(r);
  }

  /* ソート */
  void build()
  {
    order.resize(left.size());
    iota(begin(order), end(order), 0);
    sort(begin(order), end(order), [&](int a, int b)
    {
      if(left[a] / width != left[b] / width) return left[a] < left[b];
      return right[a] < right[b];
    });
  }

  /* クエリを 1 つぶんすすめて, クエリのidを返す */
  int process()
  {
    if(ptr == order.size()) return (-1);
    const auto id = order[ptr];
    while(nl > left[id]) distribute(--nl);
    while(nr < right[id]) distribute(nr++);
    while(nl < left[id]) distribute(nl++);
    while(nr > right[id]) distribute(--nr);
    return (order[ptr++]);
  }

  inline void distribute(int idx)
  {
    v[idx].flip();
    if(v[idx]) add(idx);
    else del(idx);
  }

  void add(int idx);

  void del(int idx);
};

void Mo::add(int idx)
{
  reach[sum[A[idx]]]--;
  ++sum[A[idx]];
  reach[sum[A[idx]]]++;
  if(sum[A[idx]] > now) ++now;
}

void Mo::del(int idx)
{
  reach[sum[A[idx]]]--;
  if(sum[A[idx]] == now && reach[sum[A[idx]]] == 0) --now;
  --sum[A[idx]];
  reach[sum[A[idx]]]++;
}

int main()
{
  while(scanf("%d", &N), N) {
    memset(sum, 0, sizeof(sum));
    memset(reach, 0, sizeof(reach));
    now = 0;

    scanf("%d", &M);
    for(int i = 0; i < N; i++) {
      scanf("%d", &A[i]);
      A[i] += 100000;
    }
    Mo mo(N);
    for(int i = 0; i < M; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      mo.insert(--x, y);
    }
    mo.build();
    for(int i = 0; i < M; i++) {
      ans[mo.process()] = now;
    }
    for(int i = 0; i < M; i++) {
      printf("%d\n", ans[i]);
    }
  }
}


Compiler output:
a.cc: In member function 'void Mo::build()':
a.cc:30:5: error: 'iota' was not declared in this scope
   30 |     iota(begin(order), end(order), 0);
      |     ^~~~
a.cc: In function 'int main()':
a.cc:81:5: error: 'memset' was not declared in this scope
   81 |     memset(sum, 0, sizeof(sum));
      |     ^~~~~~
a.cc:7:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    6 | #include<algorithm>
  +++ |+#include <cstring>
    7 | using namespace std;
Language: C++

#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
int N, M, A[100000], ans[100000];
int reach[100001], sum[200001], now;

struct Mo
{
  vector< int > left, right, order;
  vector< bool > v;
  int width;
  int nl, nr, ptr;

  Mo(int n) : width((int) sqrt(n)), nl(0), nr(0), ptr(0), v(n) {}

  void insert(int l, int r) /* [l, r) */
  {
    left.push_back(l);
    right.push_back(r);
  }

  /* ソート */
  void build()
  {
    order.resize(left.size());
    iota(begin(order), end(order), 0);
    sort(begin(order), end(order), [&](int a, int b)
    {
      if(left[a] / width != left[b] / width) return left[a] < left[b];
      return right[a] < right[b];
    });
  }

  /* クエリを 1 つぶんすすめて, クエリのidを返す */
  int process()
  {
    if(ptr == order.size()) return (-1);
    const auto id = order[ptr];
    while(nl > left[id]) distribute(--nl);
    while(nr < right[id]) distribute(nr++);
    while(nl < left[id]) distribute(nl++);
    while(nr > right[id]) distribute(--nr);
    return (order[ptr++]);
  }

  inline void distribute(int idx)
  {
    v[idx].flip();
    if(v[idx]) add(idx);
    else del(idx);
  }

  void add(int idx);

  void del(int idx);
};

void Mo::add(int idx)
{
  reach[sum[A[idx]]]--;
  ++sum[A[idx]];
  reach[sum[A[idx]]]++;
  if(sum[A[idx]] > now) ++now;
}

void Mo::del(int idx)
{
  reach[sum[A[idx]]]--;
  if(sum[A[idx]] == now && reach[sum[A[idx]]] == 0) --now;
  --sum[A[idx]];
  reach[sum[A[idx]]]++;
}

int main()
{
  while(scanf("%d", &N), N) {
    memset(sum, 0, sizeof(sum));
    memset(reach, 0, sizeof(reach));
    now = 0;

    scanf("%d", &M);
    for(int i = 0; i < N; i++) {
      scanf("%d", &A[i]);
      A[i] += 100000;
    }
    Mo mo(N);
    for(int i = 0; i < M; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      mo.insert(--x, y);
    }
    mo.build();
    for(int i = 0; i < M; i++) {
      ans[mo.process()] = now;
    }
    for(int i = 0; i < M; i++) {
      printf("%d\n", ans[i]);
    }
  }
}


Compiler output:
a.cc: In member function 'void Mo::build()':
a.cc:28:5: error: 'iota' was not declared in this scope
   28 |     iota(begin(order), end(order), 0);
      |     ^~~~
a.cc:29:5: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   29 |     sort(begin(order), end(order), [&](int a, int b)
      |     ^~~~
      |     sqrt
a.cc: In function 'int main()':
a.cc:79:5: error: 'memset' was not declared in this scope
   79 |     memset(sum, 0, sizeof(sum));
      |     ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include<cmath>
  +++ |+#include <cstring>
    5 | using namespace std;
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N, Q; 
    cin >> N >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i], --a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(N, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}
```

Compiler output:
a.cc:69:1: error: stray '`' in program
   69 | ```
      | ^
a.cc:69:2: error: stray '`' in program
   69 | ```
      |  ^
a.cc:69:3: error: stray '`' in program
   69 | ```
      |   ^
Language: C++

#include<iostream>
#include<cstdio>
int N, M, A[100000], ans[100000];
int reach[100001], sum[200001], now;

void Mo::add(int idx)
{
  reach[sum[A[idx]]]--;
  ++sum[A[idx]];
  reach[sum[A[idx]]]++;
  if(sum[A[idx]] > now) ++now;
}

void Mo::del(int idx)
{
  reach[sum[A[idx]]]--;
  if(sum[A[idx]] == now && reach[sum[A[idx]]] == 0) --now;
  --sum[A[idx]];
  reach[sum[A[idx]]]++;
}

int main()
{
  while(scanf("%d", &N), N) {
    memset(sum, 0, sizeof(sum));
    memset(reach, 0, sizeof(reach));
    now = 0;

    scanf("%d", &M);
    for(int i = 0; i < N; i++) {
      scanf("%d", &A[i]);
      A[i] += 100000;
    }
    Mo mo(N);
    for(int i = 0; i < M; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      mo.insert(--x, y);
    }
    mo.build();
    for(int i = 0; i < M; i++) {
      ans[mo.process()] = now;
    }
    for(int i = 0; i < M; i++) {
      printf("%d\n", ans[i]);
    }
  }
}

Compiler output:
a.cc:6:6: error: 'Mo' has not been declared
    6 | void Mo::add(int idx)
      |      ^~
a.cc:14:6: error: 'Mo' has not been declared
   14 | void Mo::del(int idx)
      |      ^~
a.cc: In function 'int main()':
a.cc:25:5: error: 'memset' was not declared in this scope
   25 |     memset(sum, 0, sizeof(sum));
      |     ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<cstdio>
  +++ |+#include <cstring>
    3 | int N, M, A[100000], ans[100000];
a.cc:34:5: error: 'Mo' was not declared in this scope; did you mean 'M'?
   34 |     Mo mo(N);
      |     ^~
      |     M
a.cc:38:7: error: 'mo' was not declared in this scope
   38 |       mo.insert(--x, y);
      |       ^~
a.cc:40:5: error: 'mo' was not declared in this scope
   40 |     mo.build();
      |     ^~
Language: C++

// https://ei1333.hateblo.jp/entry/2017/09/11/211011

#include <vector>
using namespace std;

struct Mo
{
  vector< int > left, right, order;
  vector< bool > v;
  int width;
  int nl, nr, ptr;

  Mo(int n) : width((int) sqrt(n)), nl(0), nr(0), ptr(0), v(n) {}

  void insert(int l, int r) /* [l, r) */
  {
    left.push_back(l);
    right.push_back(r);
  }

  /* ソート */
  void build()
  {
    order.resize(left.size());
    iota(begin(order), end(order), 0);
    sort(begin(order), end(order), [&](int a, int b)
    {
      if(left[a] / width != left[b] / width) return left[a] < left[b];
      return right[a] < right[b];
    });
  }

  /* クエリを 1 つぶんすすめて, クエリのidを返す */
  int process()
  {
    if(ptr == order.size()) return (-1);
    const auto id = order[ptr];
    while(nl > left[id]) distribute(--nl);
    while(nr < right[id]) distribute(nr++);
    while(nl < left[id]) distribute(nl++);
    while(nr > right[id]) distribute(--nr);
    return (order[ptr++]);
  }

  inline void distribute(int idx)
  {
    v[idx].flip();
    if(v[idx]) add(idx);
    else del(idx);
  }

  void add(int idx);

  void del(int idx);
};

int N, A[300000], Q;
int ans[200000];
int cnt[1000001], sum;

void Mo::add(int idx)
{
  if(cnt[A[idx]]++ == 0) ++sum;
}

void Mo::del(int idx)
{
  if(--cnt[A[idx]] == 0) --sum;
}

int main()
{
  scanf("%d %d", &N, &Q);
  for(int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  Mo mo(N);
  for(int i = 0; i < Q; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    mo.insert(--a, b);
  }
  mo.build();
  for(int i = 0; i < Q; i++) {
    ans[mo.process()] = sum;
  }
  for(int i = 0; i < Q; i++) {
    printf("%d\n", ans[i]);
  }
}

Compiler output:
a.cc: In constructor 'Mo::Mo(int)':
a.cc:13:27: error: 'sqrt' was not declared in this scope
   13 |   Mo(int n) : width((int) sqrt(n)), nl(0), nr(0), ptr(0), v(n) {}
      |                           ^~~~
a.cc: In member function 'void Mo::build()':
a.cc:25:5: error: 'iota' was not declared in this scope
   25 |     iota(begin(order), end(order), 0);
      |     ^~~~
a.cc:26:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   26 |     sort(begin(order), end(order), [&](int a, int b)
      |     ^~~~
      |     short
a.cc: In function 'int main()':
a.cc:73:3: error: 'scanf' was not declared in this scope
   73 |   scanf("%d %d", &N, &Q);
      |   ^~~~~
a.cc:88:5: error: 'printf' was not declared in this scope
   88 |     printf("%d\n", ans[i]);
      |     ^~~~~~
a.cc:4:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
    3 | #include <vector>
  +++ |+#include <cstdio>
    4 | using namespace std;
Language: C++

int N, M, A[100000], ans[100000];
int reach[100001], sum[200001], now;

void Mo::add(int idx)
{
  reach[sum[A[idx]]]--;
  ++sum[A[idx]];
  reach[sum[A[idx]]]++;
  if(sum[A[idx]] > now) ++now;
}

void Mo::del(int idx)
{
  reach[sum[A[idx]]]--;
  if(sum[A[idx]] == now && reach[sum[A[idx]]] == 0) --now;
  --sum[A[idx]];
  reach[sum[A[idx]]]++;
}

int main()
{
  while(scanf("%d", &N), N) {
    memset(sum, 0, sizeof(sum));
    memset(reach, 0, sizeof(reach));
    now = 0;

    scanf("%d", &M);
    for(int i = 0; i < N; i++) {
      scanf("%d", &A[i]);
      A[i] += 100000;
    }
    Mo mo(N);
    for(int i = 0; i < M; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      mo.insert(--x, y);
    }
    mo.build();
    for(int i = 0; i < M; i++) {
      ans[mo.process()] = now;
    }
    for(int i = 0; i < M; i++) {
      printf("%d\n", ans[i]);
    }
  }
}

Compiler output:
a.cc:4:6: error: 'Mo' has not been declared
    4 | void Mo::add(int idx)
      |      ^~
a.cc:12:6: error: 'Mo' has not been declared
   12 | void Mo::del(int idx)
      |      ^~
a.cc: In function 'int main()':
a.cc:22:9: error: 'scanf' was not declared in this scope
   22 |   while(scanf("%d", &N), N) {
      |         ^~~~~
a.cc:23:5: error: 'memset' was not declared in this scope
   23 |     memset(sum, 0, sizeof(sum));
      |     ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | int N, M, A[100000], ans[100000];
a.cc:32:5: error: 'Mo' was not declared in this scope; did you mean 'M'?
   32 |     Mo mo(N);
      |     ^~
      |     M
a.cc:36:7: error: 'mo' was not declared in this scope
   36 |       mo.insert(--x, y);
      |       ^~
a.cc:38:5: error: 'mo' was not declared in this scope
   38 |     mo.build();
      |     ^~
a.cc:43:7: error: 'printf' was not declared in this scope
   43 |       printf("%d\n", ans[i]);
      |       ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | int N, M, A[100000], ans[100000];
Language: C++

#include<bits/stdc++.h> 
using namespace std; 
  
const int MAX = 1000001; 
struct Query 
{ 
    int l, r, idx; 
}; 

bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 

    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 

    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 

int main() 
{ 
   	int N;
  	int Q;
  	cin>>N>>Q;
  	int arr[N+1];
  	for(int i=0; i<N; i++) cin>>arr[i];
  	Query queries[Q+1]; 
  	while(Q-->0){
    cin>>queries[i].l>>queries[i].r;
    }
    sort(queries, queries+Q, cmp); 
    answeringQueries(arr, N, queries, Q); 
    return 0; 
} 

Compiler output:
a.cc: In function 'int main()':
a.cc:70:18: error: 'i' was not declared in this scope
   70 |     cin>>queries[i].l>>queries[i].r;
      |                  ^
Language: C++

/******************
 *AUTHOR: speckrel*
 ******************/
 
#include "bits/stdc++.h"
#include<stdlib.h>
using namespace std;
 
#define ll int
 
//Function to read int array
void read(ll arr[], ll n){
    for(ll i=0;i<n;i++){
        cin>>arr[i];
    }
}
 
void solve(){
    static int i=1;
    //cout<<"This is a test code "<<i<<"\n";
    i++;
}



//col function
ll col(ll arr[], ll l, ll r){
    if(l==r){
        return 1;
    }
    ll count = 0;
    int n = 500000+1;
    int* arrhash = (int*)malloc(n, sizeof(int));
    for(int j=l;j<r;j++){
        int i = arr[j];
        arrhash[i]++;
        if(arrhash[i]==1){
            ++count;
        }
    }
    return count;
}
 
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,q;
    cin>>n>>q;
    ll arr[n];
    read(arr,n);
    for(ll i=0;i<q;i++){
        ll l,r;
        cin>>l>>r;
        l--;
        cout<<col(arr,l,r)<<"\n";
    }
    return 0;
}

Compiler output:
a.cc: In function 'int col(int*, int, int)':
a.cc:33:32: error: too many arguments to function 'void* malloc(size_t)'
   33 |     int* arrhash = (int*)malloc(n, sizeof(int));
      |                          ~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42,
                 from a.cc:5:
/usr/include/stdlib.h:672:14: note: declared here
  672 | extern void *malloc (size_t __size) __THROW __attribute_malloc__
      |              ^~~~~~
Language: C++

// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 1000001; 
 
struct Query 
{ 
	int l, r, idx; 
}; 

bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
    int n,q;
	int a[n];
    for(auto i=0; i<n;i++) cin>>a[i]; 

	Query queries[q];
    for(auto i=0; i<q;i++){
        ll ini,fnl;
        cin>>ini>>fnl;
        queries[i].l = ini-1;
        queries[i].idx = fnl-1;
    } 
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


Compiler output:
a.cc: In function 'int main()':
a.cc:74:9: error: 'll' was not declared in this scope
   74 |         ll ini,fnl;
      |         ^~
a.cc:75:14: error: 'ini' was not declared in this scope; did you mean 'int'?
   75 |         cin>>ini>>fnl;
      |              ^~~
      |              int
a.cc:75:19: error: 'fnl' was not declared in this scope; did you mean 'ynl'?
   75 |         cin>>ini>>fnl;
      |                   ^~~
      |                   ynl
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N,Q; cin >> N >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

  
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;



Compiler output:
a.cc: In function 'int main()':
a.cc:67:56: error: expected '}' at end of input
   67 |     for (int i = 0; i < Q; ++i) cout << res[i] << endl;
      |                                                        ^
a.cc:40:12: note: to match this '{'
   40 | int main() {
      |            ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
const int N = 5E5 + 5;
const int M = 5E5 + 5;
int a[N];
int b[N];
bitset<M> rst;
bitset<M> segt_a[4 * N];
bitset<M> segt_b[4 * N];
void build_a(int node, int start, int end) {
    if(start == end) {
        segt_a[node].set(a[start]);
        return;
    }
    int mid = (start + end) >> 1;
    build_a(node << 1, start, mid);
    build_a((node << 1) + 1, mid + 1, end);
    segt_a[node] = segt_a[node << 1] | segt_a[(node << 1) + 1];
    return;
}
void build_b(int node, int start, int end) {
    if(start == end) {
        segt_b[node].set(b[start]);
        return;
    }
    int mid = (start + end) >> 1;
    build_b(node << 1, start, mid);
    build_b((node << 1) + 1, mid + 1, end);
    segt_b[node] = segt_b[node << 1] | segt_b[(node << 1) + 1];
    return;
}
bitset<M> query_a(int node, int start, int end, int L, int R) {
    if(start > R || end < L)
        return rst;
    if(start >= L && end <= R)
        return segt_a[node];
    int mid = (start + end) >> 1;
    return query_a(node << 1, start, mid, L, R) | query_a((node << 1) + 1, mid + 1, end, L, R);
}
bitset<M> query_b(int node, int start, int end, int L, int R) {
    if(start > R || end < L)
        return rst;
    if(start >= L && end <= R)
        return segt_b[node];
    int mid = (start + end) >> 1;
    return query_b(node << 1, start, mid, L, R) | query_b((node << 1) + 1, mid + 1, end, L, R);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin >> n>>q;
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
    for(int i = 1; i <= n; i ++)
        b[i]=0;
    build_a(1, 1, n);
    build_b(1, 1, n);
   // int q;
    //cin >> q;
    int L1, R1, L2, R2;
    while(q --) {
        cin >> L1 >> R1;
        L2=0; R2=0;
        int ans = (query_a(1, 1, n, L1, R1) | query_b(1, 1, n, L2, R2)).count();
        cout << ans<< '\n';
    }
    return 0;
}


Compiler output:
/tmp/ccIEdVV3.o: in function `build_b(int, int, int)':
a.cc:(.text+0x14e): relocation truncated to fit: R_X86_64_PC32 against symbol `segt_b' defined in .bss section in /tmp/ccIEdVV3.o
a.cc:(.text+0x1d4): relocation truncated to fit: R_X86_64_PC32 against symbol `segt_b' defined in .bss section in /tmp/ccIEdVV3.o
a.cc:(.text+0x1ec): relocation truncated to fit: R_X86_64_PC32 against symbol `segt_b' defined in .bss section in /tmp/ccIEdVV3.o
a.cc:(.text+0x202): relocation truncated to fit: R_X86_64_PC32 against symbol `segt_b' defined in .bss section in /tmp/ccIEdVV3.o
/tmp/ccIEdVV3.o: in function `query_b(int, int, int, int, int)':
a.cc:(.text+0x45b): relocation truncated to fit: R_X86_64_PC32 against symbol `segt_b' defined in .bss section in /tmp/ccIEdVV3.o
collect2: error: ld returned 1 exit status
Language: C++

// C++ implementation of above approach 
#include <bits/stdc++.h> 
using namespace std; 

// Each segment of the segment tree would be a set 
// to maintain distinct elements 
set<int>* segment; 

// Build the segment tree 
// i denotes current node, s denotes start and 
// e denotes the end of range for current node 
void build(int i, int s, int e, int arr[]) 
{ 

	// If start is equal to end then 
	// insert the array element 
	if (s == e) { 
		segment[i].insert(arr[s]); 
		return; 
	} 

	// Else divide the range into two halves 
	// (start to mid) and (mid+1 to end) 
	// first half will be the left node 
	// and the second half will be the right node 
	build(2 * i, s, (s + e) / 2, arr); 
	build(1 + 2 * i, 1 + (s + e) / 2, e, arr); 

	// Insert the sets of right and left 
	// node of the segment tree 
	segment[i].insert(segment[2 * i].begin(), 
					segment[2 * i].end()); 

	segment[i].insert(segment[2 * i + 1].begin(), 
					segment[2 * i + 1].end()); 
} 

// Query in an range a to b 
set<int> query(int node, int l, int r, int a, int b) 
{ 
	set<int> left, right, result; 

	// If the range is out of the bounds 
	// of this segment 
	if (b < l || a > r) 
		return result; 

	// If the range lies in this segment 
	if (a <= l && r <= b) 
		return segment[node]; 

	// Else query for the right and left 
	// leaf node of this subtree 
	// and insert them into the set 
	left = query(2 * node, l, (l + r) / 2, a, b); 
	result.insert(left.begin(), left.end()); 

	right = query(1 + 2 * node, 1 + (l + r) / 2, r, a, b); 
	result.insert(right.begin(), right.end()); 

	// Return the result 
	return result; 
} 

// Initialize the segment tree 
void init(int n) 
{ 
	// Get the height of the segment tree 
	int h = (int)ceil(log2(n)); 
	h = (2 * (pow(2, h))) - 1; 

	// Initialize the segment tree 
	segment = new set<int>[h]; 
} 

// Function to get the result for the 
// subarray from arr[l] to arr[r] 
void getDistinct(int l, int r, int n) 
{ 
	// Query for the range set 
	set<int> ans = query(1, 0, n - 1, l, r); 

	cout << ans.size() << endl; 
} 

// Driver code 
int main() 
{ 

  int n,q; cin>>n>>q;
  int arr[n];
  for(int i=0;i<n;i++) ci>>arr[i];
	init(n); 

	// Bulid the segment tree 
	build(1, 0, n - 1, arr); 

	// Query in range l to r 
  while(q--)
  {
    int l,r; cin>>l>>r;
    getDistinct(l, r, n); 
  }
	

	return 0; 
} 


Compiler output:
a.cc: In function 'int main()':
a.cc:92:24: error: 'ci' was not declared in this scope; did you mean 'i'?
   92 |   for(int i=0;i<n;i++) ci>>arr[i];
      |                        ^~
      |                        i
Language: C

#include<stdio.h>
#define NUM 5*100000+10
int a[NUM]
int main(void){
    int N,Q,i,j,k=0;
    scanf("%d %d",&Q,&N);
    int c[NUM],l[NUM],r[NUM],b[NUM];
    for ( i = 0; i < N; i++){
        scanf("%d",&c[i]);
    }
    for ( i = 0; i < N; i++)
    {
        scanf("%d %d",&l[i],&r[i]);
        for ( j = l[i]-1; j < r[i]; j++)
        {
            k=0;
            do
            {
                if(a[k]==0){
                a[k]=c[j];
                k++;
                }else if(a[k]==c[j]){

                }else {k++;}
            } while (a[k]!=0||a[k]!=c[j]);
            
            

        }
        b[i]=k;
        for ( j = 0; j < k; j++)
        {
            a[j]=0;
        }
        
        
        
    }
    for ( i = 0; i < Q; i++)
    {
        printf("%d",b[i]);
    }
    

}

Compiler output:
main.c:3:11: error: expected ';' before 'int'
    3 | int a[NUM]
      |           ^
      |           ;
    4 | int main(void){
      | ~~~        
main.c: In function 'main':
main.c:19:20: error: 'a' undeclared (first use in this function)
   19 |                 if(a[k]==0){
      |                    ^
main.c:19:20: note: each undeclared identifier is reported only once for each function it appears in
Language: C++

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

template <typename T>
class segmenttree
{
private:
    ll n;

public:
    using F = function<T(T, T)>;

    T dif;
    F f;
    vector<T> st;

    segmenttree(ll size, T init, F f) : f(f)
    {
        n = 1;

        while (n < size)
        {
            n *= 2;
        }

        st.assign(2 * n - 1, init);
    }

    void set(ll i, T x)
    {
        st[i + n - 1] = x;
    }

    void build()
    {
        for (ll i = n - 2; i >= 0; i--)
        {
            st[i] = f(st[i * 2 + 1], st[i * 2 + 2]);
        }
    }

    void update(ll i, T x)
    {
        i += n - 1;
        st[i] = x;

        while (i > 0)
        {
            i = (i - 1) / 2;
            st[i] = f(st[2 * i + 1], st[2 * i + 2]);
        }
    }

    T query(ll a, ll b)
    {
        return query_(a, b, 0, 0, n);
    }

    T query_(ll a, ll b, ll k, ll l, ll r)
    {
        if (r <= a || b <= l)
        {
            return dif;
        }

        if (a <= l && r <= b)
        {
            return st[k];
        }
        else
        {
            T x = query_(a, b, 2 * k + 1, l, (l + r) / 2);
            T y = query_(a, b, 2 * k + 2, (l + r) / 2, r);

            return f(x, y);
        }
    }
};

//初期化例 segmenttree<bitset<26>> seg(n, 0, [](bitset<26> a, bitset<26> b) { return a | b; });

ll main(void)
{
    ll n, q;
    vector<ll> ans;

    cin >> n >> q;

    vector<ll> c(n);

    for (ll i = 0; i < n; i++)
    {
        cin >> c[i];
    }

    segmenttree<bitset<500010>> seg(n, 0, [](bitset<500010> a, bitset<500010> b) { return a | b; });
    seg.dif = 0;

    for (ll i = 0; i < n; i++)
    {
        bitset<500010> bit;
        bit.set(c[i]);
        seg.set(i, bit);
    }

    seg.build();

    for (ll i = 0; i < q; i++)
    {
        ll l, r;
        ll an = 0;

        cin >> l >> r;
        l--;

        bitset<500010> bit = seg.query(l, r);

        an = bit.count();

        ans.push_back(an);
    }

    for (auto &z : ans)
    {
        cout << z << endl;
    }
}

Compiler output:
a.cc:100:1: error: '::main' must return 'int'
  100 | ll main(void)
      | ^~