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

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n;
  ll k;
  cin >> n >> k;
  vecll a(n);
  REPe(e, a) cin >> e;
  sort(all(a));
  ll r = a.back();
  ll l = 1;
  // cout << a.back() << endl;
  auto check = [&](ll x) {
    ll num = 0;
    REPe(e, a) {
      if(e != x){
	      num += e / x;
      }
    if (num > k) {
      return false;
    } else {
      return true;
    }
  };

  if (check(l)) {
    cout << l << endl;
    return 0;
  }
  while (r - l > 1) {
    ll c = (r + l) / 2;
    if (check(c)) {
      r = c;
    } else {
      l = c;
    }
  }
  cout << r << endl;
}


Compiler output:
a.cc: In lambda function:
a.cc:62:7: error: use of 'check' before deduction of 'auto'
   62 |   if (check(l)) {
      |       ^~~~~
a.cc:64:12: error: inconsistent types 'bool' and 'int' deduced for lambda return type
   64 |     return 0;
      |            ^
a.cc:68:9: error: use of 'check' before deduction of 'auto'
   68 |     if (check(c)) {
      |         ^~~~~
a.cc: In function 'int main()':
a.cc:75:2: error: expected ',' or ';' at end of input
   75 | }
      |  ^
a.cc:75:2: error: expected '}' at end of input
a.cc:35:12: note: to match this '{'
   35 | int main() {
      |            ^
Language: C++

// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

typedef long long LL;
typedef long double LD;

bool possible(int n, int k, LD x, const vector<LD>& a) {
	int cnt = 0;
	for (LD d : a) {
		cnt += (int)ceil(d / x);
		--cnt;
	}
	return cnt <= k;
}

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1, k;
		cin >> n >> k;
		if (n < 0) return 0;
		vector<LD> a(n);
		for (LL i = 0; i < n; ++i) {
			cin >> a[i];
		}
		LD left = 0.1, right = 1e10;
		for (int t = 0; t < 1000; ++t) {
			LD mid = (left + right) / 2;
			if (possible(n, k, mid, a)) {
				right = mid;
			} else {
				left = mid;
			}
		}
		cout << ceil(left) << endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'bool possible(int, int, LD, const std::vector<long double>&)':
a.cc:17:29: error: 'ceil' was not declared in this scope
   17 |                 cnt += (int)ceil(d / x);
      |                             ^~~~
a.cc: In function 'int main(int, char**)':
a.cc:45:25: error: 'ceil' was not declared in this scope
   45 |                 cout << ceil(left) << endl;
      |                         ^~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[200005]={0};
int n,k;
int solve(double fun){
    int num = 0 ;
    for(int i=0;i<n;i++){
        num += a[i]/fun;
    }
    if(num<=k)
        return 1;
    return 0;
}
int main()
{
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    double l=0,r=1000000007;
    while(r-l>0.00001){
        double m = (l+r)/2;
        if(solve(m)){
            r=m;
        }
        else
            l=m-0.000001;
        //cout << l << " " << r << endl;
    }
    cout <<(int)round(r)<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:17: error: 'round' was not declared in this scope
   32 |     cout <<(int)round(r)<<endl;
      |                 ^~~~~
Language: C++

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

int n;
long long k, a[25], cut[25], tot, mx;
vector <pair<double, int> >v;
double avg, ans;

bool cmp(pair<double, int> x, pair<double, int> y){
    return x.first > y.first;
}

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        tot += a[i];
        mx = max(mx, a[i]);
    }
    if (k == 0){
        cout << mx << "\n";
        return 0;
    }
    avg = (double)tot/(k+n);
    for (int i = 1; i <= n; i++){
        cut[i] = max(1, (int)(a[i]/avg));
        k -= cut[i]-1;
        v.push_back({(double)a[i]/cut[i], i});
    }
    sort(v.begin(), v.end(), cmp);
    for (auto i:v){
        if (k){
            cut[i.second]++;
            k--;
        }
        ans = max(ans, (double)a[i.second]/cut[i.second]);
    }
    int tmp = round(ans);
    cout << tmp << "\n";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:5: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   32 |     sort(v.begin(), v.end(), cmp);
      |     ^~~~
      |     sqrt
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll>A(N);
  for (int i = 0; i < N; i ++) cin >> A[i];
  ll mi = 1;
  ll ma = 1e9;
  while (mi != ma) {
    ll mu = (mi + ma) / 2;
    ll kj = 0;
    for (int i = 0; i < N; i ++) {
      kj += ((A[i] - 1) / mu);
    }
    if (kj <= K) mi = mu + 1;
    else ma = mu;
  }
  cout << mi - 1 << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:3: error: 'll' was not declared in this scope
    5 |   ll K;
      |   ^~
a.cc:6:15: error: 'K' was not declared in this scope
    6 |   cin >> N >> K;
      |               ^
a.cc:7:12: error: template argument 2 is invalid
    7 |   vector<ll>A(N);
      |            ^
a.cc:8:40: error: invalid types 'int[int]' for array subscript
    8 |   for (int i = 0; i < N; i ++) cin >> A[i];
      |                                        ^
a.cc:9:5: error: expected ';' before 'mi'
    9 |   ll mi = 1;
      |     ^~~
      |     ;
a.cc:10:5: error: expected ';' before 'ma'
   10 |   ll ma = 1e9;
      |     ^~~
      |     ;
a.cc:11:10: error: 'mi' was not declared in this scope
   11 |   while (mi != ma) {
      |          ^~
a.cc:11:16: error: 'ma' was not declared in this scope; did you mean 'fma'?
   11 |   while (mi != ma) {
      |                ^~
      |                fma
a.cc:12:7: error: expected ';' before 'mu'
   12 |     ll mu = (mi + ma) / 2;
      |       ^~~
      |       ;
a.cc:13:7: error: expected ';' before 'kj'
   13 |     ll kj = 0;
      |       ^~~
      |       ;
a.cc:15:7: error: 'kj' was not declared in this scope
   15 |       kj += ((A[i] - 1) / mu);
      |       ^~
a.cc:15:16: error: invalid types 'int[int]' for array subscript
   15 |       kj += ((A[i] - 1) / mu);
      |                ^
a.cc:15:27: error: 'mu' was not declared in this scope
   15 |       kj += ((A[i] - 1) / mu);
      |                           ^~
a.cc:17:9: error: 'kj' was not declared in this scope
   17 |     if (kj <= K) mi = mu + 1;
      |         ^~
a.cc:17:23: error: 'mu' was not declared in this scope
   17 |     if (kj <= K) mi = mu + 1;
      |                       ^~
a.cc:18:15: error: 'mu' was not declared in this scope
   18 |     else ma = mu;
      |               ^~
a.cc:20:11: error: 'mi' was not declared in this scope
   20 |   cout << mi - 1 << endl;
      |           ^~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
    int i,n,l,r,mid,cnt,ans=1e9,tot;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;i++)cin>>a[i];
    l=1;r=1e9+5;
    while(l<=r){
        mid=(l+r)/2;tot=0;
        for(i=1;i<=n;i++){
            cnt=(a[i]+mid-1)/mid;
            cnt--;
            tot+=cnt;
        }
        if(tot>k){
            l=mid+1;
        }else{ans=mid;r=mid-1;}
    }cout<<ans;
    return 0;
}

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:17:16: error: 'k' was not declared in this scope
   17 |         if(tot>k){
      |                ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len)
{
  long long Ans=0;
  for(int i=0;i<N;i++)
  {
    Ans+=(long long)(X[i]/len);
  }
  return Ans;
}
int main()
{
  long long K;
  cin>>N>>K;
  for(int i=0;i<N;i++)
{
	cin>>X[i];
	X[i]-=0.1;
}
  long double l=1,r=1e12;
  while(l<r-0.1)
  {
 //   long double mid=(l+r+0.1)/2;
    cout<<l<<" "<<r<<" "<<mid<<endl;
    if(Count(mid)<=K)
      r=mid;
    else	l=mid+0.01;
  }
  cout<<(long long)(l+0.999)<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:27: error: 'mid' was not declared in this scope
   27 |     cout<<l<<" "<<r<<" "<<mid<<endl;
      |                           ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len)
{
  long long Ans=0;
  for(int i=0;i<N;i++)
  {
    Ans+=(long long)(X[i]/len);
  }
  return Ans;
}
int main()
{
  long long K;
  cin>>N>>K;
  for(int i=0;i<N;i++)
{
	cin>>X[i];
	X[i]-=0.1;
}
  long double l=1,r=1e18;
  while(l<r-0.1)
  {
 //   long double mid=(l+r+0.1)/2;
    cout<<l<<" "<<r<<" "<<mid<<endl;
    if(Count(mid)<=K)
      r=mid;
    else	l=mid+0.1;
  }
  cout<<(long long)(l+0.999)<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:27: error: 'mid' was not declared in this scope
   27 |     cout<<l<<" "<<r<<" "<<mid<<endl;
      |                           ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N, K;
  
  N, K = 3, 0, 3, 4, 5;
    
    cout << N, K << 5 << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:23: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'
   10 |     cout << N, K << 5 << endl;
      |                ~~~~~~~^~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N, K;
  
  N, K = 3, 0, 3, 4, 5
    
    cout << N, K << 5 << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:23: error: expected ';' before 'cout'
    8 |   N, K = 3, 0, 3, 4, 5
      |                       ^
      |                       ;
    9 | 
   10 |     cout << N, K << 5 << endl;
      |     ~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define int long long

void check(int n, int k, vector<int> a, int m) {
	int cuts_need = 0;
	for (int i: a) {
		cuts_need += (i-1)/m;
	}
	return cuts_need <= k;
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
		
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	int lo = 0, hi = 1000000000;
	while (lo < hi) {
		int mid = (lo + hi)/2;

		if (check(n, k, a, mid)) {
			hi = mid;
		} else {
			lo = mid+1;
		}
	}
	cout << lo << '\n';

	return 0;
}


Compiler output:
a.cc: In function 'void check(long long int, long long int, std::vector<long long int>, long long int)':
a.cc:11:26: error: return-statement with a value, in function returning 'void' [-fpermissive]
   11 |         return cuts_need <= k;
      |                ~~~~~~~~~~^~~~
a.cc: In function 'int main()':
a.cc:25:26: error: could not convert 'check(n, k, std::vector<long long int>(a), mid)' from 'void' to 'bool'
   25 |                 if (check(n, k, a, mid)) {
      |                     ~~~~~^~~~~~~~~~~~~~
      |                          |
      |                          void
Language: C++

#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
#include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


template<typename T>
class BIT{
    public:
        vector<T> x_list;
        ll n;

        BIT(ll n=1, T fill_value=0): n(n){
            x_list.resize(n+1);
            fill(x_list.begin(), x_list.end(), fill_value);
        }

        void add(ll idx, T v){
            for(ll x=idx; x<= n;x += (x & -x)){
                x_list[x] += v;
            }
        }

        ll get_sum(ll idx){
            T v = 0;
            for(ll x=idx;x>0;x-=(x & -x)){
                v += x_list[x];
            }
            return v;
        }
};

void Main(){
    ll N, Q, c, l, r;
    cin >> N >> Q;
    vector<ll> as(N);
    vector<pll> qs(Q);
    vector<pll> qs_org(Q);
    vector<ll> ans(Q);
    rep(i, N){
        cin >> as[i];
    }

    rep(i, Q){
        cin >> l >> r;
        -- l;
        -- r;
        qs[i] = make_pair(r, i);
        qs_org[i] = make_pair(r, l);
    }

    sort(qs.begin(), qs.end());

    map<ll,ll> color_best;
    ll now_r = qs[0].first;

    BIT<ll> bitree(N, 0);

    rep(i, now_r+1){
        if(color_best.find(as[i])!=color_best.end()){
            bitree.add(color_best[as[i]]+1, -1);
            bitree.add(i+1, 1);
        }else{
            bitree.add(i+1, 1);
        }
        color_best[as[i]] = i;
    }

    rep(i, Q){
        // cout << "q index = " << i << " " << qs[i]  << " now_r="<<now_r <<endl;
        // cout << color_best <<endl;
        while(now_r <= qs[i].first){
            if(color_best.find(as[now_r]) == color_best.end()){
                bitree.add(now_r+1, 1);
            }else{
                bitree.add(color_best[as[now_r]]+1, -1);
                bitree.add(now_r+1, 1);
            }
            color_best[as[now_r]] = now_r;
            ++ now_r;
        }

        ll search_l = qs_org[qs[i].second].second;
        ll this_ans = bitree.get_sum(search_l);
        ll this_ans2 = bitree.get_sum(qs[i].first+1);
        ans[qs[i].second] = this_ans2 - this_ans;
    }

    rep(i, Q){
        cout << ans[i] <<endl;
    }

}

int main(){
    Main();
}

Compiler output:
a.cc:16:10: fatal error: prettyprint.hpp: No such file or directory
   16 | #include <prettyprint.hpp>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
Language: Java

class BIT:
    def __init__(self,n):
        self.n = n
        self.tree = [0]*(n+1)

    def sum(self,x):
        sum = 0
        while(x>0):
            sum+=self.tree[x]
            x-=x&(-x)
        return sum

    def update(self,x,k):
        while(x<=self.n):
            self.tree[x]+=k
            x+=x&(-x)

    def build(self,a):
        for i in range(len(a)):
            k = a[i]
            x = i+1
            while(x<=self.n):
                self.tree[x]+=k
                x+=x&(-x)
class Query:
    def __init__(self, r,l, idx):
        self.l = l
        self.r = r
        self.idx = idx

def solve(case):
    n,q = map(int,input().split())
    c = list(map(int,input().split()))
    query = []
    for i in range(q):
        l,r = map(int,input().split())
        query.append(Query(r,l,i))

    query.sort(key = lambda x:x.r)
    bit = BIT(n)
    lastvis = [-1]*(n+1)
    ind = 0
    ans = [0]*q
    for i in range(n):
        if(lastvis[c[i]] != -1):
            bit.update(lastvis[c[i]]+1,-1)

        lastvis[c[i]] = i
        bit.update(i+1,1)
        while(ind<q and query[ind].r == i+1):
            ans[query[ind].idx] = (bit.sum(i+1) - bit.sum(query[ind].l-1))
            ind+=1

    # print('\n'.join(str(ans[i]) for i in range(len(ans))))
    for i in range(q):
        print(ans[i])
solve(1)


Compiler output:
Main.java:1: error: '{' expected
class BIT:
         ^
Main.java:25: error: '{' expected
class Query:
           ^
Main.java:32: error: class, interface, enum, or record expected
    n,q = map(int,input().split())
              ^
Main.java:54: error: illegal character: '#'
    # print('\n'.join(str(ans[i]) for i in range(len(ans))))
    ^
4 errors
Language: C++

#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

class Mo{
  public:
  vector<int> l,r,ord;
  vector<bool> is;
  int wid,nl,nr,ptr;
  Mo(int n) : wid((int)sqrt(n)),nl(0),nr(0),ptr(0),is(n){}
  // add queries [l, r)
  void insert(int &a,int &b){
    l.push_back(a);
    r.push_back(b);
  }
  // after all insert()
  void build(){
    ord.resize(l.size());
    iota(ALL(ord),0);
    sort(ALL(ord),[&](int a,int b){
      if(l[a]/wid != l[b]/wid)return l[a] < l[b];
      else return r[a] < r[b];
    });
  }
  int process(){
    if(ptr == ord.size())return -1;
    const int idx = ord[ptr++];
    while(nl < l[idx])distribute(nl++);
    while(nl > l[idx])distribute(--nl);
    while(nr > r[idx])distribute(--nr);
    while(nr < r[idx])distribute(nr++);
    return idx;
  }
  void distribute(int &idx){
    is[idx].flip();
    if(is[idx])add(idx);
    else del(idx);
  }
  void add(int &idx);
  void del(int &idx);
};
vector<int> v(500010);
vector<int> cnt(500010);
vector<int> res(500010);
int sum = 0;

void Mo::add(int &idx){
  cnt[v[idx]]++;
  if(cnt[v[idx]] == 1)sum++;
}
void Mo::del(int &idx){
  cnt[v[idx]]--;
  if(cnt[v[idx]] == 0)sum--;
}


int main(){
  
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,Q;
  cin >> n >> Q;
  rep(i,n)cin >> v[i];
  Mo mo(n);
  rep(_,Q){
    int l,r;cin >> l >> r;
    mo.insert(--l,r);
  }
  mo.build();
  rep(_,Q){
    int idx = mo.process();
    res[idx] = sum;
  }
  rep(i,Q)cout << res[i] << "\n";



  return 0;
}

Compiler output:
a.cc: In member function 'int Mo::process()':
a.cc:36:36: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   36 |     while(nl < l[idx])distribute(nl++);
      |                                  ~~^~
a.cc:42:24: note:   initializing argument 1 of 'void Mo::distribute(int&)'
   42 |   void distribute(int &idx){
      |                   ~~~~~^~~
a.cc:39:36: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   39 |     while(nr < r[idx])distribute(nr++);
      |                                  ~~^~
a.cc:42:24: note:   initializing argument 1 of 'void Mo::distribute(int&)'
   42 |   void distribute(int &idx){
      |                   ~~~~~^~~
Language: C++

#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = (m); i < (int)(n); i++)

int main() {
    int N, Q, l, r, idx = 0;
    cin >> N >> Q;
    vector<int> c(N), good(N, -1), ans(N);
    REP(i, N) cin >> c[i];
    vector<tuple<int, int, int>> query(Q);
    REP(i, Q) {
        cin >> l >> r;
        query[i] = {r - 1, l - 1, i};
    }

    sort(query.begin(), query.end());
    fenwick_tree<int> fw(N);

    REP(i, Q) {
        l = get<1>(query[i]);
        r = get<0>(query[i]);
        // printf("%d,%d\n", l, r);
        // goodを更新する
        // 合わせてBIT木も更新する
        while (idx <= r) {
            if (good[c[idx] - 1] >= 0) {
                fw.add(good[c[idx] - 1], -1);
            }
            good[c[idx] - 1] = idx;
            fw.add(idx, 1);
            idx++;
        }
        ans[get<2>(query[i])] = fw.sum(l, r + 1);
    }

    REP(i, Q) cout << ans[i] << endl;
}

Compiler output:
a.cc:3:10: fatal error: atcoder/all: No such file or directory
    3 | #include <atcoder/all>
      |          ^~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define chmax(a,b) a=max(a,b)
int n,Q,bl;
int c[500005];
int ans=0,cnt[500005];
struct query{
	int l,r,id;
}q[500005];
int qans[500005];
bool cmp(query a,query b){
	return (a.r/bl)==(b.r/bl)?a.l<b.l:a.r<b.r;
}
void add(int x){
	if(!cnt[c[x]]){
		ans++;
	}
	cnt[c[x]]++;
}
void del(int x){
	cnt[c[x]]--;
	if(!cnt[c[x]]){
		ans--;
	}
}
int main(){
	cin>>n>>Q;
	bl=n/sqrt(m*2/3);
	for(int i=1;i<=n;++i){
		cin>>c[i];
	}
	for(int i=1;i<=Q;++i){
		cin>>q[i].l>>q[i].r;
		q[i].id=i;
	}
	sort(q+1,q+1+Q,cmp);
	int l=0,r=0;
	for(int i=1;i<=Q;++i){
		int ql=q[i].l,qr=q[i].r;
//		cout<<ql<<' '<<qr<<'\n';
		while(l<ql){
			del(l);
			l++;
		}
		while(l>ql){
			l--;
			add(l);
		}
		while(r>qr){
			del(r);
			r--;
		}
		while(r<qr){
			r++;
			add(r);
		}
		qans[q[i].id]=ans;
	}
	for(int i=1;i<=Q;++i){
		cout<<qans[i]<<'\n';
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:19: error: 'm' was not declared in this scope; did you mean 'tm'?
   29 |         bl=n/sqrt(m*2/3);
      |                   ^
      |                   tm
Language: C

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
 
const int N = (int) 5e5 + 7;
const int M = 777;
 
int n, q, v[N], sol[N], magic, bucket[N], last[N], first[N], f[N];
 
struct T {
  int l;
  int r;
  int i;
};
 
vector<T> lol[M];
 
bool operator < (T a, T b) {
  return a.r < b.r;
}
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  magic = sqrt(n);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    bucket[i] = (i - 1) / magic + 1;
    last[bucket[i]] = i;
  }
  for (int i = n; i >= 1; i--) {
    first[bucket[i]] = i;
  }
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    lol[bucket[l]].push_back({l, r, i});
  }
  for (int b = bucket[1]; b <= bucket[n]; b++) {
    for (int i = 1; i <= n; i++) {
      f[v[i]] = 0;
    }
    sort(lol[b].begin(), lol[b].end());
    int until = last[b], jmek = 0;
    for (auto &it : lol[b]) {
      if (it.r <= last[b]) {
        int element = 0;
        for (int j = it.l; j <= it.r; j++) {
          f[v[j]]++;
          element += (f[v[j]] == 1);
        }
        for (int j = it.l; j <= it.r; j++) {
          f[v[j]] = 0;
        }
        sol[it.i] = element;
      } else {
        while (until < it.r) {
          until++;
          f[v[until]]++;
          jmek += (f[v[until]] == 1);
        }
        int element = jmek;
        for (int j = it.l; j <= last[b]; j++) {
          f[v[j]]++;
          element += (f[v[j]] == 1);
        }
        for (int j = it.l; j <= last[b]; j++) {
          f[v[j]]--;
        }
        sol[it.i] = element;
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << sol[i] << "\n";
  }
  return 0;
}


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

const int dm = 1 << 17;
char *dn = cn, * di = dn, * owad = dn + dm - 20;
inline void putint(int X) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	int dig = 1;
	if (X >= 10000) {
		if (X >= 100000) dig = 6;
		else dig = 5;
	}
	else {
		if (X >= 1000) dig = 4;
		else if (X >= 100) dig = 3;
		else if (X >= 10) dig = 2;
	}
	rep1(i, dig) {
		di[dig - i] = '0' + X % 10;
		X /= 10;
	}
	di[dig] = '\n';
	di += dig + 1;
}

Compiler output:
a.cc:2:12: error: 'cn' was not declared in this scope; did you mean 'dn'?
    2 | char *dn = cn, * di = dn, * owad = dn + dm - 20;
      |            ^~
      |            dn
a.cc: In function 'void putint(int)':
a.cc:4:13: error: 'owad' was not declared in this scope
    4 |         if (owad < di) {
      |             ^~~~
a.cc:4:20: error: 'di' was not declared in this scope; did you mean 'dn'?
    4 |         if (owad < di) {
      |                    ^~
      |                    dn
a.cc:5:40: error: 'stdout' was not declared in this scope
    5 |                 fwrite(dn, 1, di - dn, stdout);
      |                                        ^~~~~~
a.cc:1:1: note: 'stdout' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | const int dm = 1 << 17;
a.cc:5:17: error: 'fwrite' was not declared in this scope
    5 |                 fwrite(dn, 1, di - dn, stdout);
      |                 ^~~~~~
a.cc:18:14: error: 'i' was not declared in this scope
   18 |         rep1(i, dig) {
      |              ^
a.cc:18:9: error: 'rep1' was not declared in this scope
   18 |         rep1(i, dig) {
      |         ^~~~
a.cc:22:9: error: 'di' was not declared in this scope; did you mean 'dig'?
   22 |         di[dig] = '\n';
      |         ^~
      |         dig
Language: C++

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

template<typename T>
struct ST{
  using F = function<T(T, T)>;
  int size_ = 1, n_; vector<T> node; F query_;
  ST(int n, F query){
    while(size_ < n) size_ *= 2;
    node.resize(2*size_-1);
    n_ = n;
    query_ = query;
  }
  void build(vector<T> v){
    for(int i = 0; i < (int)v.size(); ++i) node[i+size_-1] = v[i];
    for(int i = size_ - 2; i >= 0; --i) node[i] = query_(node[2*i+1], node[2*i+2]);
    return;
  }
  T query(int l, int r){
    l += size_-1;
    r += size_-1;
    T ql = node[l], qr = node[r];
    while(l < r-1){
      if(l % 2 == 1) ql = query_(ql, node[l+1]);
      if(r % 2 == 0) qr = query_(node[r-1], qr);
      l = (l-1)/2;
      r = (r-1)/2;
    }
    return query_(ql, qr);
  }
};

int main(){
  int n, q; cin >> n >> q;
  auto f = [](int a, int b){return a+b;};
  ST<int> st(n, f);
  vi1 v(n); rep(i, n) cin >> v[i];
  rep(i, q){
    int l, r; cin >> l >> r;
    v1i u(r, 0); unordered_set<int> us;
    rrep(i, r){
      if(us.count(v[i])) continue;
      us.insert(v[i]); u[i] = 1;
    }
    st.build(u);
    cout << st.query(l-1, r-1) << endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:63:3: error: 'vi1' was not declared in this scope; did you mean 'v1i'?
   63 |   vi1 v(n); rep(i, n) cin >> v[i];
      |   ^~~
      |   v1i
a.cc:63:30: error: 'v' was not declared in this scope
   63 |   vi1 v(n); rep(i, n) cin >> v[i];
      |                              ^
a.cc:68:19: error: 'v' was not declared in this scope
   68 |       if(us.count(v[i])) continue;
      |                   ^
a.cc:69:17: error: 'v' was not declared in this scope
   69 |       us.insert(v[i]); u[i] = 1;
      |                 ^
Language: C++

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

template<typename T>
struct ST{
  using F = function<T(T, T)>;
  int size_ = 1, n_; vector<T> node; F query_;
  ST(int n, F query){
    while(size_ < n) size_ *= 2;
    node.resize(2*size_-1);
    n_ = n;
    query_ = query;
  }
  void build(vector<T> v){
    for(int i = 0; i < (int)v.size(); ++i) node[i+size_-1] = v[i];
    for(int i = size_ - 2; i >= 0; --i) node[i] = query_(node[2*i+1], node[2*i+2]);
    return;
  }
  T query(int l, int r){
    l += size_-1;
    r += size_-1;
    T ql = node[l], qr = node[r];
    while(l < r-1){
      if(l % 2 == 1) ql = query_(ql, node[l+1]);
      if(r % 2 == 0) qr = query_(node[r-1], qr);
      l = (l-1)/2;
      r = (r-1)/2;
    }
    return query_(ql, qr);
  }
};

int main(){
  int n, q; cin >> n >> q;
  auto f = [](unordered_set<int>s1, unordered_set<int>s2){
    for(int tmp: s2){s1.insert(tmp);} return s1;
  }
  ST<unordered_set<int>> st(n, f);
  vector<unordered_set<int>> v(n);
  rep(i, n){
    int in; cin >> in; v[i].insert(in);
  }
  st.build(v);
  rep(i, q){
    int ans, l, r; cin >> l >> r;
    ans = st.query(l, r).size();
    cout << ans << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:64:3: error: expected ',' or ';' before 'ST'
   64 |   ST<unordered_set<int>> st(n, f);
      |   ^~
a.cc:69:3: error: 'st' was not declared in this scope; did you mean 'std'?
   69 |   st.build(v);
      |   ^~
      |   std
Language: C++

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

template<typename T>
struct ST{
  using F = function<T(T, T)>;
  int size_ = 1, n_; vector<T> node; F query_;
  ST(int n, F query){
    while(size_ < n) size_ *= 2;
    node.resize(2*size_-1);
    n_ = n;
    query_ = query;
  }
  void build(vector<T> v){
    for(int i; i < v.size(); ++i) node[i+size_-1] = v[i];
    for(int i = size_ - 2; i >= 0; --i) node[i] = query_(node[2*i+1], node[2*i+2]);
    return;
  }
  T query(int l, int r){
    l += size_-1;
    r += size_-1;
    T ql = node[l], qr = node[r];
    while(l < r-1){
      if(l % 2 == 1) ql = query_(ql, node[l+1]);
      if(r % 2 == 0) qr = query_(node[r-1], qr);
      l = (l-1)/2;
      r = (r-1)/2;
    }
    return query_(ql, qr);
  }
};

int main(){
  int n, q; cin >> n >> q;
  auto f = [](unordered_set<int>s1, unordered_set<int>s2){
    for(int tmp: s2){s1.insert(tmp);} return s1;
  }
  ST<unordered_set<int>> st(n, f);
  vector<unordered_set<int>> v(n);
  rep(i, n){
    int in; cin >> in; v[i].insert(in);
  }
  st.build(v);
  rep(i, q){
    int ans, l, r; cin >> l >> r;
    ans = st.query(l, r).size();
    cout << ans << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:64:3: error: expected ',' or ';' before 'ST'
   64 |   ST<unordered_set<int>> st(n, f);
      |   ^~
a.cc:69:3: error: 'st' was not declared in this scope; did you mean 'std'?
   69 |   st.build(v);
      |   ^~
      |   std
Language: C++

#include <bits/stdc++.h> 
using namespace std; 
  
// Each segment of the segment tree would be a set 
// to maintain distinct elements 
set<int> segment[2000006]; 
int arr[500005];  
// 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) 
{ 
  
    // 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); 
    build(1 + 2 * i, 1 + (s + e) / 2, e); 
  

    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]; 

    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]; 
} 
  
void getDistinct(int l, int r, int n) 
{ 
    set<int> ans = query(1, 0, n - 1, l, r); 
  
    cout << ans.size() << endl; 
} 
  
// Driver code 
int main() 
{ 
  	int n,q;
  	cin >> n >> q;
  	for(int i = 0; i < n; i++){
      	cin >> arr[i];
    	arr[i]--;
    }
  
  
    build(1, 0, n - 1); 
  	while(q--){
    	int l,r;
      	cin >> l >> r;
      	getDistinct(l - 1, r - 1, n); 
    }
    
  
    return 0; 
} 


Compiler output:
a.cc: In function 'void init(int)':
a.cc:68:13: error: incompatible types in assignment of 'std::set<int>*' to 'std::set<int> [2000006]'
   68 |     segment = new set<int>[h];
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h> 
using namespace std; 
  
// Each segment of the segment tree would be a set 
// to maintain distinct elements 
unordered_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); 
  

    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 
unordered_set<int> query(int node, int l, int r, int a, int b) 
{ 
    unordered_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]; 

    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]; 
} 
  
void getDistinct(int l, int r, int n) 
{ 
    unordered_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++)
      	cin >> arr[i];
  
    init(n); 
  
    build(1, 0, n - 1, arr); 
  	while(q--){
    	int l,r;
      	cin >> l >> r;
      	getDistinct(l - 1, r - 1, n); 
    }
    
  
    return 0; 
} 


Compiler output:
a.cc: In function 'void init(int)':
a.cc:68:15: error: cannot convert 'std::set<int>*' to 'std::unordered_set<int>*' in assignment
   68 |     segment = new set<int>[h];
      |               ^~~~~~~~~~~~~~~
      |               |
      |               std::set<int>*
Language: C++

#include <bits/stdc++.h> 
using namespace std; 

unoredered_set<int> segment[1000006]; 
int n;
int arr[500005];

void build(int i, int s, int e) 
{ 
    if (s == e) { 
        segment[i].insert(arr[s]); 
        return; 
    } 
    build(2 * i, s, (s + e) / 2); 
    build(1 + 2 * i, 1 + (s + e) / 2, e); 
    segment[i].insert(segment[2 * i].begin(), 
                      segment[2 * i].end()); 
  
    segment[i].insert(segment[2 * i + 1].begin(), 
                      segment[2 * i + 1].end()); 
} 
  
unoredered_set<int> query(int node, int l, int r, int a, int b) 
{ 
    unoredered_set<int> left, right, result; 
 
    if (b < l || a > r) 
        return result; 
    if (a <= l && r <= b) 
        return segment[node]; 
    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 result; 
} 
  
  
// 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 
    unoredered_set<int> ans = query(1, 0, n - 1, l, r); 
  
    cout << ans.size() << endl; 
} 
  
int main() 
{ 
  	int q;
  	cin >> n >> q;;
  	for(int i = 1; i <= n; i++)
      cin >> arr[i];
    build(1, 1, n); 
  	while(q--){
      int i,j;
      cin >> i >> j;
      getDistinct(i, j, n); 
    }
    return 0; 
} 


Compiler output:
a.cc:4:1: error: 'unoredered_set' does not name a type
    4 | unoredered_set<int> segment[1000006];
      | ^~~~~~~~~~~~~~
a.cc: In function 'void build(int, int, int)':
a.cc:11:9: error: 'segment' was not declared in this scope
   11 |         segment[i].insert(arr[s]);
      |         ^~~~~~~
a.cc:16:5: error: 'segment' was not declared in this scope
   16 |     segment[i].insert(segment[2 * i].begin(),
      |     ^~~~~~~
a.cc: At global scope:
a.cc:23:1: error: 'unoredered_set' does not name a type
   23 | unoredered_set<int> query(int node, int l, int r, int a, int b)
      | ^~~~~~~~~~~~~~
a.cc: In function 'void getDistinct(int, int, int)':
a.cc:45:5: error: 'unoredered_set' was not declared in this scope
   45 |     unoredered_set<int> ans = query(1, 0, n - 1, l, r);
      |     ^~~~~~~~~~~~~~
a.cc:45:20: error: expected primary-expression before 'int'
   45 |     unoredered_set<int> ans = query(1, 0, n - 1, l, r);
      |                    ^~~
a.cc:47:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   47 |     cout << ans.size() << endl;
      |             ^~~
      |             abs
Language: C++

#include <bits/stdc++.h> 
using namespace std; 

set<int> segment[500005]; 
int n;
int arr[500005];

void build(int i, int s, int e) 
{ 
    if (s == e) { 
        segment[i].insert(arr[s]); 
        return; 
    } 
    build(2 * i, s, (s + e) / 2); 
    build(1 + 2 * i, 1 + (s + e) / 2, e); 
    segment[i].insert(segment[2 * i].begin(), 
                      segment[2 * i].end()); 
  
    segment[i].insert(segment[2 * i + 1].begin(), 
                      segment[2 * i + 1].end()); 
} 
  
set<int> query(int node, int l, int r, int a, int b) 
{ 
    set<int> left, right, result; 
 
    if (b < l || a > r) 
        return result; 
    if (a <= l && r <= b) 
        return segment[node]; 
    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 result; 
} 
  
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; 
} 
  
int main() 
{ 
  	int q;
  	cin >> n >> q;;
  	for(int i = 1; i <= n; i++)
      cin >> arr[i];
    init(n); 
    build(1, 1, n); 
  	while(q--){
      int i,j;
      cin >> i >> j;
      getDistinct(i, j, n); 
    }
    return 0; 
} 


Compiler output:
a.cc: In function 'void init(int)':
a.cc:46:13: error: incompatible types in assignment of 'std::set<int>*' to 'std::set<int> [500005]'
   46 |     segment = new set<int>[h];
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h> 
using namespace std; 

set<int>* segment; 
int n;
int arr[500005];

void build(int i, int s, int e) 
{ 
    if (s == e) { 
        segment[i].insert(arr[s]); 
        return; 
    } 
    build(2 * i, s, (s + e) / 2); 
    build(1 + 2 * i, 1 + (s + e) / 2, e); 
    segment[i].insert(segment[2 * i].begin(), 
                      segment[2 * i].end()); 
  
    segment[i].insert(segment[2 * i + 1].begin(), 
                      segment[2 * i + 1].end()); 
} 
  
set<int> query(int node, int l, int r, int a, int b) 
{ 
    set<int> left, right, result; 
 
    if (b < l || a > r) 
        return result; 
    if (a <= l && r <= b) 
        return segment[node]; 
    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 result; 
} 
  
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 q;
  	cin >> n >> q;;
  	for(int i = 1; i <= n; i++)
      cin >> arr[i];
    init(n); 
    build(1, 0, n - 1, arr); 
  	while(q--){
      int i,j;
      cin >> i >> j;
      getDistinct(i, j, n); 
    }
    return 0; 
} 

Compiler output:
a.cc: In function 'int main()':
a.cc:67:10: error: too many arguments to function 'void build(int, int, int)'
   67 |     build(1, 0, n - 1, arr);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
a.cc:8:6: note: declared here
    8 | void build(int i, int s, int e)
      |      ^~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#pragma gcc optimize("O3")
#pragma gcc optimize("unroll-loops")
#ifdef EVAH
    #define _WIN32_WINNT 0x0500
    #include<windows.h>
#endif
#define openFile(n) ShellExecute(nullptr,"open",n,nullptr,nullptr,SW_SHOWNORMAL);
#define closeP(n) system((string("taskkill /im ")+n+" /f").c_str());
#define closeConsole PostMessage(GetConsoleWindow(), WM_CLOSE, 0, 0);
#define opf "output.txt"
#define ipf "input.txt"
#define mem(n,x) memset(n,x,sizeof(n));
#define sf scanf
#define pf printf
#define ff first
#define ss second
#define pb push_back
#define PII pair<int,int>
#define For(x,n) for(int i=x; i<n; i++)
#define stv v+2*(mid-tl+1)
#define LL long long int
#define PI acos(-1.0)
#define N 500001

int blockSize;

struct query {
    int l,r,idx;
    bool operator<(query other) const {
        if(l/blockSize != other.l/blockSize) return l<other.l;
        return (l/blockSize&1) ? (r<other.r) : (r>other.r);
    }
};

vector<int> clr(N),appeared(N);
int tempAns = 0;

void rmv(int idx) {
    appeared[clr[idx]]--;
    if(!appeared[clr[idx]]) tempAns--;
}
void add(int idx) {
    if(!appeared[clr[idx]]) tempAns++;
    appeared[clr[idx]]++;
}
int get_ans() {
    return tempAns;
}

vector<int> mosAlgo(vector<query> queries) {
    vector<int> ans(queries.size());
    sort(queries.begin(),queries.end(),comp);
    int curL = 0;
    int curR = -1;
    for(query q : queries) {
        while(curL > q.l) {
            curL--;
            add(curL);
        }
        while(curR < q.r) {
            curR++;
            add(curR);
        }
        while(curL < q.l) {
            rmv(curL);
            curL++;
        }
        while(curR > q.r) {
            rmv(curR);
            curR--;
        }
        ans[q.idx] = get_ans();
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    #ifdef EVAH
        //freopen(ipf,"r",stdin);
        //openFile(ipf);
        //closeConsole;
        //freopen(opf,"w",stdout);
    #endif

    int n,q,l,r;
    cin >> n >> q;
    blockSize = sqrt(n);
    vector<query> queries(q);
    For(0,n) {
        cin >> clr[i];
    }
    For(0,q) {
        queries[i].idx = i;
        cin >> queries[i].l >> queries[i].r;
        queries[i].l--;
        queries[i].r--;
    }
    vector<int> ans = mosAlgo(queries);
    For(0,ans.size()) {
        cout << ans[i] << "\n";
    }

    #ifdef EVAH
        //openFile(opf);
        //Sleep(3000);
        //closeP("notepad.exe");
        //closeConsole;
    #endif
}


Compiler output:
a.cc: In function 'std::vector<int> mosAlgo(std::vector<query>)':
a.cc:54:40: error: 'comp' was not declared in this scope
   54 |     sort(queries.begin(),queries.end(),comp);
      |                                        ^~~~